{"id":2824,"date":"2014-08-14T01:45:21","date_gmt":"2014-08-13T16:45:21","guid":{"rendered":"http:\/\/apr20.net\/?p=2824"},"modified":"2014-08-14T01:45:21","modified_gmt":"2014-08-13T16:45:21","slug":"%e9%87%8d%e8%a4%87%e3%81%97%e3%81%aa%e3%81%84wordpress%e3%81%aedescription%e8%a8%ad%e5%ae%9a","status":"publish","type":"post","link":"https:\/\/apr20.net\/?p=2824","title":{"rendered":"\u91cd\u8907\u3057\u306a\u3044WordPress\u306edescription\u8a2d\u5b9a"},"content":{"rendered":"<p>\u91cd\u8907\u3057\u306a\u3044WordPress\u306edescription\u306e\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n<br \/>\n\u304a\u304a\u307e\u304b\u306a\u78ba\u8a8d\u306f\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u7d30\u304b\u3044\u30c1\u30a7\u30c3\u30af\u306f\u51fa\u6765\u3066\u307e\u305b\u3093\u30fb\u30fb\u30fbm(_ _)m\n<\/p>\n<p><a href=\"https:\/\/gist.github.com\/apr20\/afdbcaf378c86dd93641\" target=\"_blank\">Gist\u306f\u3053\u3061\u3089<\/a><\/p>\n<p>[php]&lt;?php<\/p>\n<p>\/\/description\u306e\u8a2d\u5b9a<br \/>\nfunction set_description(){<br \/>\n\tglobal $post;<br \/>\n\t$content = $post-&gt;post_content;<\/p>\n<p>\t\/\/\u30c8\u30c3\u30d7\u30da\u30fc\u30b8<br \/>\n\tif ( is_front_page() ) {<br \/>\n\t\t$desc = get_bloginfo(&#8216;name&#8217;).&quot;:&quot;.get_bloginfo(&#8216;description&#8217;);<br \/>\n\t}else{<br \/>\n\t\tif(is_page() or is_single()){ \/\/\u56fa\u5b9a\u30da\u30fc\u30b8\u3001\u8a18\u4e8b\u30da\u30fc\u30b8<br \/>\n\t\t\t\/\/php\u30bf\u30b0\u3092\u9664\u53bb<br \/>\n\t\t\t$content = preg_replace(&quot;\/&lt;\\?php[^&gt;]+\\&gt;\/i&quot;,&quot; &quot;,$content);<br \/>\n\t\t\t\/\/html\u30bf\u30b0\u3092\u9664\u53bb<br \/>\n\t\t\t$desc = wp_title(&#8221;,false).&quot; | &quot;.strip_tags($content);<br \/>\n\t\t}elseif( is_category()){ \/\/\u30ab\u30c6\u30b4\u30ea\u30da\u30fc\u30b8<br \/>\n\t\t\tif(get_query_var(&#8216;paged&#8217;)){<br \/>\n\t\t\t\t$desc = get_query_var(&#8216;paged&#8217;).&quot;\u30da\u30fc\u30b8\u76ee:&quot;;<br \/>\n\t\t\t}<br \/>\n\t\t\t$desc .= wp_title(&#8221;,false).&quot;\u30ab\u30c6\u30b4\u30ea\u306e\u8a18\u4e8b\u4e00\u89a7&quot;;<br \/>\n\t\t}elseif( is_archive()){ \/\/\u30a2\u30fc\u30ab\u30a4\u30d6\u30da\u30fc\u30b8<br \/>\n\t\t\tif(is_date()){ \/\/\u65e5\u4ed8\u30d9\u30fc\u30b9\u306e\u30a2\u30fc\u30ab\u30a4\u30d6\u30da\u30fc\u30b8<br \/>\n\t\t\t\tif(is_day()){ \/\/\u65e5\u5225\u30a2\u30fc\u30ab\u30a4\u30d6<br \/>\n\t\t\t\t\tif(get_query_var(&#8216;paged&#8217;)){<br \/>\n\t\t\t\t\t\t$desc = get_query_var(&#8216;paged&#8217;).&quot;\u30da\u30fc\u30b8\u76ee:&quot;;<br \/>\n\t\t\t\t\t}<br \/>\n\t\t\t\t\t$desc.= get_the_time(&#8216;Y&#8217;). &#8216;\u5e74&#8217;;<br \/>\n\t\t\t\t\t$desc.= get_the_time(&#8216;m&#8217;) .&#8217;\u6708&#8217;;<br \/>\n\t\t\t\t\t$desc.= get_the_time(&#8216;d&#8217;). &#8216;\u65e5&#8217;;<br \/>\n\t\t\t\t}elseif(is_month()){ \/\/\u6708\u5225\u30a2\u30fc\u30ab\u30a4\u30d6<br \/>\n\t\t\t\t\tif(get_query_var(&#8216;paged&#8217;)){<br \/>\n\t\t\t\t\t\t$desc = get_query_var(&#8216;paged&#8217;).&quot;\u30da\u30fc\u30b8\u76ee:&quot;;<br \/>\n\t\t\t\t\t}<br \/>\n\t\t\t\t\t$desc.= get_the_time(&#8216;Y&#8217;) .&#8217;\u5e74&#8217;;<br \/>\n\t\t\t\t\t$desc.= get_the_time(&#8216;m&#8217;). &#8216;\u6708&#8217;;<br \/>\n\t\t\t\t}else { \/\/\u5e74\u5225\u30a2\u30fc\u30ab\u30a4\u30d6<br \/>\n\t\t\t\t\tif(get_query_var(&#8216;paged&#8217;)){<br \/>\n\t\t\t\t\t\t$desc = get_query_var(&#8216;paged&#8217;).&quot;\u30da\u30fc\u30b8\u76ee:&quot;;<br \/>\n\t\t\t\t\t}<br \/>\n\t\t\t\t\t$desc.= get_the_time(&#8216;Y&#8217;) .&#8217;\u5e74&#8217;;<br \/>\n\t\t\t\t}<br \/>\n\t\t\t}elseif(is_author()){ \/\/\u6295\u7a3f\u8005\u30a2\u30fc\u30ab\u30a4\u30d6<br \/>\n\t\t\t\tif(get_query_var(&#8216;paged&#8217;)){<br \/>\n\t\t\t\t\t$desc = get_query_var(&#8216;paged&#8217;).&quot;\u30da\u30fc\u30b8\u76ee:&quot;;<br \/>\n\t\t\t\t}<br \/>\n\t\t\t\t$desc .='[\u6295\u7a3f\u8005:&#8217;. get_the_author_meta(&#8216;display_name&#8217;, get_query_var(&#8216;author&#8217;)).&quot;]&quot;;<br \/>\n\t\t\t}elseif(is_tag()){\t\/\/\u30bf\u30b0\u30a2\u30fc\u30ab\u30a4\u30d6<br \/>\n\t\t\t\tif(get_query_var(&#8216;paged&#8217;)){<br \/>\n\t\t\t\t\t$desc = get_query_var(&#8216;paged&#8217;).&quot;\u30da\u30fc\u30b8\u76ee:&quot;;<br \/>\n\t\t\t\t}<br \/>\n\t\t\t\t$desc.='[\u30bf\u30b0:&#8217;. single_tag_title( &#8221; , false ).&quot;]&quot;;<br \/>\n\t\t\t}else{<br \/>\n\t\t\t\tif(get_query_var(&#8216;paged&#8217;)){<br \/>\n\t\t\t\t\t$desc = get_query_var(&#8216;paged&#8217;).&quot;\u30da\u30fc\u30b8\u76ee:&quot;;<br \/>\n\t\t\t\t}<br \/>\n\t\t\t\t$desc .= wp_title(&#8221;,false);<br \/>\n\t\t\t}<br \/>\n\t\t\t$desc .= &quot;\u306e\u8a18\u4e8b\u4e00\u89a7&quot;;<br \/>\n\t\t}elseif(is_search()) {\t\/\/\u691c\u7d22\u7d50\u679c<br \/>\n\t\t\tif(get_query_var(&#8216;paged&#8217;)){<br \/>\n\t\t\t\t$desc = get_query_var(&#8216;paged&#8217;).&quot;\u30da\u30fc\u30b8\u76ee:&quot;;<br \/>\n\t\t\t}<br \/>\n\t\t\t$desc.= &#8216;[&#8216;. get_search_query() .&#8217;]\u306e\u691c\u7d22\u7d50\u679c\u4e00\u89a7&#8217;;<\/p>\n<p>\t\t}else{<br \/>\n\t\t\tif(get_query_var(&#8216;paged&#8217;)){<br \/>\n\t\t\t\t$desc = get_query_var(&#8216;paged&#8217;).&quot;\u30da\u30fc\u30b8\u76ee:&quot;;<br \/>\n\t\t\t}<br \/>\n\t\t\t$desc .= wp_title(&#8221;,false);<br \/>\n\t\t}<\/p>\n<p>\t\t\/\/description\u304c\u77ed\u3059\u304e\u308b\u5834\u5408\u306f\u30b5\u30a4\u30c8\u6982\u8981\u3001\u30b5\u30a4\u30c8\u540d\u8ffd\u52a0<br \/>\n\t\tif(mb_strlen($desc)&lt;=30){<br \/>\n\t\t\t$desc .= &quot; &quot;.get_bloginfo(&#8216;description&#8217;).&quot;\u3010&quot;.get_bloginfo(&#8216;name&#8217;).&quot;\u3011&quot;;<br \/>\n\t\t}<\/p>\n<p>\t}<br \/>\n\t\/\/\u56fa\u5b9a\u30da\u30fc\u30b8\u3001\u8a18\u4e8b\u30da\u30fc\u30b8\u306e\u672c\u6587\u629c\u7c8b\u306e\u6539\u884c\u524a\u9664<br \/>\n\t$desc = str_replace(array(&quot;\\r\\n&quot;,&quot;\\r&quot;,&quot;\\n&quot;), &#8221;, $desc);<br \/>\n\techo &#8216;&lt;meta name=&quot;description&quot; content=&quot;&#8217;.esc_html($desc).&#8217;&quot;&gt;&#8217;;<br \/>\n}<br \/>\n\/\/description\u306e\u8a2d\u5b9a<\/p>\n<p>?&gt;[\/php]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u91cd\u8907\u3057\u306a\u3044WordPress\u306edescription\u306e\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,18,2,5],"tags":[],"class_list":["post-2824","post","type-post","status-publish","format-standard","hentry","category-php","category-seo","category-web","category-wordpress-web-category"],"_links":{"self":[{"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/posts\/2824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2824"}],"version-history":[{"count":0,"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/posts\/2824\/revisions"}],"wp:attachment":[{"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}