{"id":3390,"date":"2017-02-09T08:50:57","date_gmt":"2017-02-08T23:50:57","guid":{"rendered":"http:\/\/agn.jp\/blog\/?p=3390"},"modified":"2017-02-08T15:47:35","modified_gmt":"2017-02-08T06:47:35","slug":"%e3%81%a8%e3%82%8a%e3%81%82%e3%81%88%e3%81%9afunctions-php%e3%81%ab%e6%9b%b8%e3%81%84%e3%81%a8%e3%81%8f%e3%81%a8%e4%be%bf%e5%88%a9%e3%81%8b%e3%82%82%e3%81%97%e3%82%8c%e3%81%aa%e3%81%84%e3%82%b7","status":"publish","type":"post","link":"http:\/\/agn.jp\/blog\/?p=3390","title":{"rendered":"\u3068\u308a\u3042\u3048\u305afunctions.php\u306b\u66f8\u3044\u3068\u304f\u3068\u4fbf\u5229\u304b\u3082\u3057\u308c\u306a\u3044\u30b7\u30ea\u30fc\u30ba\u3010WordPress\u3011"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/agn.jp\/blog\/wp-content\/uploads\/2017\/02\/agnblog170208.png\" alt=\"\" width=\"1024\" height=\"538\" class=\"aligncenter size-full wp-image-3392\" srcset=\"http:\/\/agn.jp\/blog\/wp-content\/uploads\/2017\/02\/agnblog170208.png 1024w, http:\/\/agn.jp\/blog\/wp-content\/uploads\/2017\/02\/agnblog170208-300x158.png 300w, http:\/\/agn.jp\/blog\/wp-content\/uploads\/2017\/02\/agnblog170208-768x404.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>\u4eca\u5e74\u306e\u96ea\u306f\u6025\u306b\u3084\u3063\u3066\u304d\u305f\u308a\u3044\u306a\u304f\u306a\u3063\u305f\u308a\u3001\u5fd9\u3057\u3044\u5929\u6c17\u3067\u3059\u306d\u3002<br \/>\nWordPress\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3092\u3057\u3066\u3044\u3066\u3001\u306a\u3093\u3060\u304b\u6bce\u56defunctions.php\u306b\u540c\u3058\u3053\u3068\u66f8\u3044\u3066\u308b\u3053\u3068\u304c\u5897\u3048\u305f\u306e\u3067\u5099\u5fd8\u9332\u4ee3\u308f\u308a\u306b\u3002<br \/>\n\u5b9a\u756a\u306e\u3082\u306e\u304b\u3089\u5c0f\u30cd\u30bf\u307e\u3067\u3002<\/p>\n<h2>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u5468\u308a<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-title=\"\">remove_action(&#039;wp_head&#039;, &#039;wp_generator&#039;);\nremove_action(&#039;wp_head&#039;, &#039;rsd_link&#039;);\nremove_action(&#039;wp_head&#039;, &#039;wlwmanifest_link&#039;);\nremove_action(&#039;wp_head&#039;, &#039;wp_shortlink_wp_head&#039;);\nremove_action(&#039;wp_head&#039;, &#039;adjacent_posts_rel_link_wp_head&#039;);<\/pre>\n<p>\u3069\u5b9a\u756a\u3067\u3059\u304c\u307e\u3041\u3002\u5b9a\u756a\u3063\u3066\u3053\u3068\u306f\u4fbf\u5229\u3063\u3066\u3053\u3068\u3067\u3059\u3002<\/p>\n<h3>\u56fa\u5b9a\u30da\u30fc\u30b8\u540d\u3092body\u306e\u30af\u30e9\u30b9\u540d\u3068\u3057\u3066\u8ffd\u52a0<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-title=\"\">function pagename_class($classes = &#039;&#039;) {\nif(is_page()) {\n    $page = get_post(get_the_ID());\n    $classes[] = $page-&gt;post_name .&#039; page_&#039; .$page-&gt;post_name;\n}\nreturn $classes;\n}\nadd_filter(&#039;body_class&#039;,&#039;pagename_class&#039;);<\/pre>\n<p>\u30da\u30fc\u30b8\u540d\u306e\u30af\u30e9\u30b9\u304c\u3042\u3063\u305f\u307b\u3046\u304cCSS\u66f8\u304f\u6642\u4fbf\u5229\u3067\u3059\u304b\u3089\u306d\u3002<\/p>\n<h3>CSS\u3001Javascript\u306e\u8aad\u307f\u8fbc\u307f<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-title=\"\">function theme_enqueue_styles() {\n    \/\/ \u89aa\u30c6\u30fc\u30de\u306estyle.css\n    wp_enqueue_style( &#039;parent-style&#039;, get_template_directory_uri() . &#039;\/style.css&#039; );\n    \/\/ \u5b50\u30c6\u30fc\u30de\u306estyle.css\n    wp_enqueue_style( &#039;child-style&#039;,\n        get_stylesheet_directory_uri() . &#039;\/style.css&#039;,\n        array(&#039;parent-style&#039;)\n    );\n}\nadd_action( &#039;wp_enqueue_scripts&#039;, &#039;theme_enqueue_styles&#039; );<\/pre>\n<p>\u3053\u308c\u306f\u5b50\u30c6\u30fc\u30de\u3067\u30c6\u30fc\u30de\u3092\u4f5c\u3063\u3066\u3044\u304f\u5834\u5408\u306b\u306a\u308a\u307e\u3059\u304c\u3002<\/p>\n<h3>\u89aa\u30c6\u30fc\u30de\u306e\u4e0d\u8981\u306aCSS\u3092\u524a\u9664<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-title=\"\">function my_dequeue_styles() {\n    wp_dequeue_style( $handle );\n}\nadd_action( &#039;wp_enqueue_scripts&#039;, &#039;my_dequeue_styles&#039;, 9999 );<\/pre>\n<p>\u9006\u306b\u89aa\u30c6\u30fc\u30de\u306eCSS\u3067\u4e0d\u8981\u306aCSS\u3092\u8aad\u307f\u8fbc\u307f\u305f\u304f\u306a\u3044\u6642\u306b\u3002<br \/>\n$handle\u63a2\u3059\u306e\u306b\u624b\u9593\u53d6\u3063\u305f\u308a\u3082\u3057\u307e\u3059\u304c\u3002\u3002<\/p>\n<h2>\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u95a2\u9023<\/h2>\n<h3>\u81ea\u52d5\u3067\u5165\u529b\u3055\u308c\u308bP\u30bf\u30b0\u3092\u5165\u308c\u306a\u3044\u3002<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-title=\"\">if(is_page()){\n    remove_filter(&#039;the_content&#039;, &#039;wpautop&#039;);\n    remove_filter(&#039;the_excerpt&#039;, &#039;wpautop&#039;);\n}<\/pre>\n<p>\u8a18\u4e8b(POST)\u306f\u304a\u5ba2\u3055\u3093\u304c\u4f7f\u3046\u3053\u3068\u3082\u8003\u616e\u3057\u3066\u56fa\u5b9a\u30da\u30fc\u30b8\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<h3>\u30a6\u30a3\u30b8\u30a7\u30c3\u30c8\u30a8\u30ea\u30a2\u3092\u8ffd\u52a0<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-title=\"\">function my_widgets(){\n    register_sidebar(array(\n        &#039;name&#039; =&gt; &#039;\u30a6\u30a3\u30b8\u30c3\u30c8\u540d&#039;, \n        &#039;description&#039; =&gt; &#039;\u30c6\u30ad\u30b9\u30c8\u30c6\u30ad\u30b9\u30c8\u30c6\u30ad\u30b9\u30c8\u30c6\u30ad\u30b9\u30c8\u30c6\u30ad\u30b9\u30c8&#039;,\n        &#039;id&#039; =&gt; &#039;widgetID&#039;,\n        &#039;class&#039; =&gt; &#039;className&#039;,\n        &#039;before_widget&#039; =&gt; &#039;&lt;aside id=&quot;%1$s&quot; class=&quot;widget %2$s&quot;&gt;&#039;,\n        &#039;after_widget&#039;  =&gt; &#039;&lt;\/aside&gt;&#039;,\n        &#039;before_title&#039;  =&gt; &#039;&lt;h2 class=&quot;widget-title&quot;&gt;&#039;,\n        &#039;after_title&#039;   =&gt; &#039;&lt;\/h2&gt;&#039;,\n    ));\n}\nadd_action(&#039;widgets_init&#039;, &#039;my_widgets&#039;);<\/pre>\n<p>\u8ffd\u52a0\u3057\u305f\u3089\u5229\u7528\u3057\u305f\u3044\u5834\u6240\u306b<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-title=\"\">&lt;?php\n    dynamic_sidebar( $number );\n    \/\/ $number\u306f\u30b5\u30a4\u30c9\u30d0\u30fc\u306e\u540d\u524d\u307e\u305f\u306f ID\u3002\n?&gt;<\/pre>\n<h3>\u6295\u7a3f\u306e\u753b\u50cf\u76f8\u5bfe\u30d1\u30b9\u3092\u7d76\u5bfe\u30d1\u30b9\u306b\u66f8\u304d\u63db\u3048<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-title=\"\">function replaceImagePath($arg) {\n    $content = str_replace(&#039;&quot;images\/&#039;, &#039;&quot;&#039; . get_stylesheet_directory_uri() . &#039;\/images\/&#039;, $arg);\n        return $content;\n}\nadd_action(&#039;the_content&#039;, &#039;replaceImagePath&#039;);<\/pre>\n<p>\u30bd\u30fc\u30b9\u3092\u30da\u30bf\u30c3\u3068WordPress\u306b\u8cbc\u308a\u4ed8\u3051\u3066\u3001\u3042\u308c\u308c\u3001\u76f8\u5bfe\u30d1\u30b9\u304c\u5207\u308c\u305f\u3002\u3092\u306a\u304f\u3059\u3088\u3046\u3002<br \/>\n\u81ea\u5206\u306e\u30c6\u30fc\u30de\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u76f4\u4e0b\u306bimages\u30d5\u30a9\u30eb\u30c0\u304c\u3042\u308b\u5834\u5408\u3067\u3059\u3002<br \/>\n\u30d1\u30b9\u306f\u9069\u5b9c\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u5c0f\u30cd\u30bf\u3067\u3059\u304c\u4ee5\u5916\u3068\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<h3>\u30b5\u30a4\u30c8\u540d\u306e\u30b7\u30e7\u30fc\u30c8\u30b3\u30fc\u30c9<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-title=\"\">function shortcode_siteurl() {\n    return home_url() .&#039;\/&#039;;\n}\nadd_shortcode(&#039;siteurl&#039;, &#039;shortcode_siteurl&#039;);<\/pre>\n<p>\u3053\u308c\u3082\u4e0a\u3068\u4f3c\u305f\u3088\u3046\u306a\u3082\u3093\u3067\u3059\u304c\u3001WordPress\u306e\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u30fc\u3067\u30ea\u30f3\u30af\u8cbc\u3063\u305f\u308a\u3059\u308b\u6642\u306b\u3002<br \/>\n\u81ea\u5206\u3067\u306f\u3042\u3093\u307e\u308a\u30b7\u30e7\u30fc\u30c8\u30b3\u30fc\u30c9\u306f\u4f7f\u308f\u306a\u3044\u3093\u3067\u3059\u3051\u3069\u3002<br \/>\n\u3044\u308d\u3044\u308d\u306a\u4eba\u304c\u4f7f\u3046\u5834\u5408\u306f\u3042\u308b\u3068\u91cd\u5b9d\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2>\u5c0f\u30cd\u30bf<\/h2>\n<h3>Advanced Custom Fields\u3067\u753b\u50cf\u306e\u30d1\u30b9\u3092\u53d6\u5f97(ID\u5229\u7528)<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-title=\"\">function get_afc_imgurl($slug){\n    if(get_field($slug)){\n        \/\/\u753b\u50cf(\u8fd4\u308a\u5024\u306f\u300c\u753b\u50cfID\u300d)\n        $img = get_field($slug);\n        $imgurl = wp_get_attachment_image_src($img[&#039;id&#039;], &#039;full&#039;); \/\/\u30b5\u30a4\u30ba\u306f\u81ea\u7531\u306b\u5909\u66f4   \n\n        return $imgurl[0]; \n    }\n}<\/pre>\n<p>\u57fa\u672c\u306fthe_field()\u3060\u3051\u3067\u51fa\u529b\u3067\u304d\u3061\u3083\u3046\u304a\u624b\u8efd\u3055\u3082Advance Custom Field\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u9b45\u529b\u306e\u4e00\u3064\u3002<br \/>\n\u753b\u50cf\u306e\u6642(ID\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u5834\u5408)\u306b\u30d1\u30b9\u306e\u51fa\u529b\u5fd8\u308c\u308b\u3053\u3068\u304c\u591a\u304b\u3063\u305f\u306e\u3067\u95a2\u6570\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<h2>\u611f\u60f3<\/h2>\n<p>\u7c21\u5358\u306a\u3082\u306e\u3070\u304b\u308a\u3067\u3059\u3051\u3069\u3002<br \/>\n\u6700\u8fd1\u306fset_query_var()\u3067\u5909\u6570\u3092get_template_part()\u306b\u6e21\u3057\u3066get_query_var()\u3067\u53d7\u3051\u3066\u3054\u306b\u3087\u3054\u306b\u3087\u3063\u3066\u3044\u3046\u306e\u304c\u3061\u3087\u3063\u3068\u304a\u6c17\u306b\u5165\u308a\u3067\u3059\u3002<br \/>\n\u56fa\u5b9a\u30da\u30fc\u30b8\u306e\u5185\u5bb9\u306a\u3093\u304b\u3082\u30d5\u30a1\u30a4\u30eb\u5207\u308a\u5206\u3051\u3066\u30da\u30fc\u30b8\u30e2\u30b8\u30e5\u30fc\u30eb\u307f\u305f\u3044\u306b\u3057\u3061\u3083\u3046\u3068\u7d50\u69cb\u697d\u3067\u3002<\/p>\n<p>\u3084\u308a\u65b9\u306f\u4eba\u305d\u308c\u305e\u308c\u3060\u3068\u601d\u3044\u307e\u3059\u3001\u4f55\u304b\u4f7f\u3048\u305d\u3046\u306a\u3082\u306e\u304c\u3042\u3063\u305f\u3089\u3069\u3046\u305e\u3054\u5229\u7528\u304f\u3060\u3055\u3044\u3002<\/p>\n<div class='wp_social_bookmarking_light'>        <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/http:\/\/agn.jp\/blog\/?p=3390\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"\u3068\u308a\u3042\u3048\u305afunctions.php\u306b\u66f8\u3044\u3068\u304f\u3068\u4fbf\u5229\u304b\u3082\u3057\u308c\u306a\u3044\u30b7\u30ea\u30fc\u30ba\u3010WordPress\u3011\" data-hatena-bookmark-layout=\"simple-balloon\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img loading=\"lazy\" decoding=\"async\" src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>        <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"http:\/\/agn.jp\/blog\/?p=3390\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>        <div class=\"wsbl_facebook_share\"><div id=\"fb-root\"><\/div><fb:share-button href=\"http:\/\/agn.jp\/blog\/?p=3390\" type=\"button_count\" ><\/fb:share-button><\/div>        <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"http:\/\/agn.jp\/blog\/?p=3390\" data-text=\"\u3068\u308a\u3042\u3048\u305afunctions.php\u306b\u66f8\u3044\u3068\u304f\u3068\u4fbf\u5229\u304b\u3082\u3057\u308c\u306a\u3044\u30b7\u30ea\u30fc\u30ba\u3010WordPress\u3011\" data-lang=\"ja\">Tweet<\/a><\/div>        <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"http:\/\/agn.jp\/blog\/?p=3390\" ><\/g:plusone><\/div><\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5e74\u306e\u96ea\u306f\u6025\u306b\u3084\u3063\u3066\u304d\u305f\u308a\u3044\u306a\u304f\u306a\u3063\u305f\u308a\u3001\u5fd9\u3057\u3044\u5929\u6c17\u3067\u3059\u306d\u3002 WordPress\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3092\u3057\u3066\u3044\u3066\u3001\u306a\u3093\u3060\u304b\u6bce\u56defunctions.php\u306b\u540c\u3058\u3053\u3068\u66f8\u3044\u3066\u308b\u3053\u3068\u304c\u5897\u3048\u305f\u306e\u3067\u5099\u5fd8\u9332\u4ee3\u308f\u308a\u306b\u3002 \u5b9a\u756a\u306e\u3082\u306e\u304b\u3089\u5c0f\u30cd\u30bf\u307e\u3067 &hellip; <a href=\"http:\/\/agn.jp\/blog\/?p=3390\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">\u3068\u308a\u3042\u3048\u305afunctions.php\u306b\u66f8\u3044\u3068\u304f\u3068\u4fbf\u5229\u304b\u3082\u3057\u308c\u306a\u3044\u30b7\u30ea\u30fc\u30ba\u3010WordPress\u3011<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":3392,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[8],"tags":[],"class_list":["post-3390","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"http:\/\/agn.jp\/blog\/wp-content\/uploads\/2017\/02\/agnblog170208.png","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/agn.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/agn.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/agn.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/agn.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/agn.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3390"}],"version-history":[{"count":0,"href":"http:\/\/agn.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3390\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/agn.jp\/blog\/index.php?rest_route=\/wp\/v2\/media\/3392"}],"wp:attachment":[{"href":"http:\/\/agn.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/agn.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3390"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/agn.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}