{"id":7227,"date":"2025-01-14T15:23:17","date_gmt":"2025-01-14T06:23:17","guid":{"rendered":"https:\/\/code-plus.jp\/gp\/?p=7227"},"modified":"2026-01-08T11:16:43","modified_gmt":"2026-01-08T02:16:43","slug":"post-7227","status":"publish","type":"post","link":"https:\/\/code-plus.jp\/gp\/post-7227\/","title":{"rendered":"WordPress\u306e\u30d1\u30f3\u304f\u305a\u30ea\u30b9\u30c8\u306e\u4f5c\u308a\u65b9\u3068\u30ab\u30b9\u30bf\u30de\u30a4\u30ba"},"content":{"rendered":"<p>WordPress\u3067\u30d1\u30f3\u304f\u305a\u30ea\u30b9\u30c8\u3092\u5b9f\u88c5\u3059\u308b\u65b9\u6cd5\u3068\u3001\u30ea\u30f3\u30af\u5148\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\r\n<h2>\u57fa\u672c\u7684\u306a\u30d1\u30f3\u304f\u305a\u30ea\u30b9\u30c8\u306e\u5b9f\u88c5<\/h2>\r\n<p>\u307e\u305a\u3001<code>breadcrumb.php<\/code>\u3092\u4f5c\u6210\u3057\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u5b9f\u88c5\u3057\u307e\u3059\uff1a<\/p>\r\n<pre><code class=\"language-php\">&lt;nav class=&quot;breadcrumb mx-auto py-1r&quot;&gt;\r\n  &lt;ul class=&quot;breadcrumb-wrapper&quot;&gt;\r\n    &lt;!-- \u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u3078\u306e\u30ea\u30f3\u30af --&gt;\r\n    &lt;li&gt;&lt;a href=&quot;&lt;?php echo do_shortcode(&#39;https:\/\/code-plus.jp\/gp&#39;); ?&gt;\/&quot;&gt;&lt;i&gt;&lt;\/i&gt;\u30c8\u30c3\u30d7&lt;\/a&gt;&lt;\/li&gt;\r\n\r\n    &lt;?php if (is_single() &amp;&amp; get_post_type() === &#39;post&#39;) : ?&gt;\r\n      &lt;!-- \u901a\u5e38\u306e\u6295\u7a3f\u30da\u30fc\u30b8 --&gt;\r\n      &lt;li&gt;&lt;a href=&quot;&lt;?php echo do_shortcode(&#39;https:\/\/code-plus.jp\/gp&#39;); ?&gt;\/posts\/&quot;&gt;\u6295\u7a3f\u4e00\u89a7&lt;\/a&gt;&lt;\/li&gt;\r\n      &lt;li&gt;&lt;a href=&quot;&lt;?php echo do_shortcode(&#39;https:\/\/code-plus.jp\/gp&#39;); ?&gt;\/category\/&lt;?php echo do_shortcode(&#39;wordpress&#39;); ?&gt;\/&quot;&gt;\r\n        &lt;?php echo do_shortcode(&#39;WordPress&#39;); ?&gt;\r\n      &lt;\/a&gt;&lt;\/li&gt;\r\n      &lt;li class=&quot;current_page_item&quot;&gt;&lt;a&gt;\r\n        &lt;?php echo wp_strip_all_tags(do_shortcode(&#39;WordPress\u306e\u30d1\u30f3\u304f\u305a\u30ea\u30b9\u30c8\u306e\u4f5c\u308a\u65b9\u3068\u30ab\u30b9\u30bf\u30de\u30a4\u30ba&#39;), false); ?&gt;\r\n      &lt;\/a&gt;&lt;\/li&gt;\r\n\r\n    &lt;?php elseif (is_singular() &amp;&amp; !is_page() &amp;&amp; get_post_type() !== &#39;post&#39;) : ?&gt;\r\n      &lt;!-- \u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u30da\u30fc\u30b8 --&gt;\r\n      &lt;li&gt;&lt;a href=&quot;&lt;?php echo do_shortcode(&#39;https:\/\/code-plus.jp\/gp&#39;); ?&gt;\/category\/&lt;?php echo do_shortcode(&#39;wordpress&#39;); ?&gt;\/&quot;&gt;\r\n        &lt;?php echo do_shortcode(&#39;WordPress&#39;); ?&gt;\r\n      &lt;\/a&gt;&lt;\/li&gt;\r\n      &lt;li class=&quot;current_page_item&quot;&gt;&lt;a&gt;\r\n        &lt;?php echo wp_strip_all_tags(do_shortcode(&#39;WordPress\u306e\u30d1\u30f3\u304f\u305a\u30ea\u30b9\u30c8\u306e\u4f5c\u308a\u65b9\u3068\u30ab\u30b9\u30bf\u30de\u30a4\u30ba&#39;), false); ?&gt;\r\n      &lt;\/a&gt;&lt;\/li&gt;\r\n\r\n    &lt;?php else : ?&gt;\r\n      &lt;!-- \u56fa\u5b9a\u30da\u30fc\u30b8\u306a\u3069 --&gt;\r\n      &lt;?php\r\n      \/\/\u5148\u7956 \u2192 \u89aa\u306e\u9806\u306b\u4e26\u3079\u66ff\u3048\r\n      $ancestors_ids = array_reverse(get_post_ancestors($post));\r\n      \/\/\u7e70\u308a\u8fd4\u3057\u3067\u5148\u7956\u30da\u30fc\u30b8\u540d\u3092\u8868\u793a\r\n      foreach ($ancestors_ids as $ancestors_id) {\r\n        echo &#39;&lt;li&gt;&lt;a href=&quot;&#39; . get_page_link($ancestors_id) . &#39;&quot;&gt;&#39;;\r\n        echo wp_strip_all_tags(get_page($ancestors_id)-&gt;post_title, false);\r\n        echo &#39;&lt;\/a&gt;&lt;\/li&gt;&#39;;\r\n      }\r\n      ?&gt;\r\n      &lt;li class=&quot;current_page_item&quot;&gt;&lt;a&gt;\r\n        &lt;?php echo wp_strip_all_tags(do_shortcode(&#39;WordPress\u306e\u30d1\u30f3\u304f\u305a\u30ea\u30b9\u30c8\u306e\u4f5c\u308a\u65b9\u3068\u30ab\u30b9\u30bf\u30de\u30a4\u30ba&#39;), false); ?&gt;\r\n      &lt;\/a&gt;&lt;\/li&gt;\r\n    &lt;?php endif; ?&gt;\r\n\r\n  &lt;\/ul&gt;\r\n&lt;\/nav&gt;\r\n<\/code><\/pre>\r\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306b\u3088\u308a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u968e\u5c64\u69cb\u9020\u304c\u8868\u73fe\u3055\u308c\u307e\u3059\uff1a<\/p>\r\n<ul style=\"list-style-type:bullet;\">\r\n<li>\u6295\u7a3f\u30da\u30fc\u30b8\u306e\u5834\u5408\uff1a<ul style=\"list-style-type:bullet;\">\r\n<li>\u30c8\u30c3\u30d7 &gt; \u6295\u7a3f\u4e00\u89a7 &gt; \u30ab\u30c6\u30b4\u30ea\u30fc\u540d1 &gt; \u8a18\u4e8b\u30bf\u30a4\u30c8\u30eb<\/li>\r\n<\/ul>\r\n<\/li>\r\n<li>\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u306e\u5834\u5408\uff1a<ul style=\"list-style-type:bullet;\">\r\n<li>\u30c8\u30c3\u30d7 &gt; \u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u4e00\u89a7 &gt; \u30ab\u30c6\u30b4\u30ea\u30fc\u540d2 &gt; \u8a18\u4e8b\u30bf\u30a4\u30c8\u30eb<\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\r\n<h2>\u56fa\u5b9a\u30da\u30fc\u30b8\u306e\u89aa\u5b50\u95a2\u4fc2\u3092\u5224\u5b9a\u3059\u308b\u30b3\u30fc\u30c9\uff08functions.php\uff09<\/h2>\r\n<pre><code class=\"language-php\">function page_is_ancestor_of($slug) {\r\n  global $post;\r\n  $page = get_page_by_path($slug);\r\n  $result = false;\r\n\r\n  if (isset($page) &amp;&amp; is_object($post) &amp;&amp; isset($post-&gt;ancestors)) {\r\n    foreach ((array)$post-&gt;ancestors as $ancestor) {\r\n      if ($ancestor == $page-&gt;ID) {\r\n        $result = true;\r\n      }\r\n    }\r\n  }\r\n\r\n  return $result;\r\n}\r\n<\/code><\/pre>\r\n<h2>\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u30ea\u30f3\u30af\u5148\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba<\/h2>\r\n<p>\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u30ea\u30f3\u30af\u5148\u3092\u5909\u66f4\u3057\u305f\u3044\u5834\u5408\u3001WordPress\u306e\u30ea\u30e9\u30a4\u30c8\u30eb\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<code>functions.php<\/code>\u306b\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\uff1a<\/p>\r\n<pre><code class=\"language-php\">function custom_rewrite_rules() {\r\n    $rules = [\r\n        &#39;category\/cat-name-1\/?$&#39; =&gt; &#39;posts\/category1\/&#39;,\r\n        &#39;category\/cat-name-2\/?$&#39; =&gt; &#39;posts\/category2\/&#39;,\r\n        &#39;category\/cat-name-3\/?$&#39; =&gt; &#39;posts\/category3\/&#39;\r\n    ];\r\n\r\n    foreach ($rules as $regex =&gt; $redirect) {\r\n        add_rewrite_rule(\r\n            $regex,\r\n            $redirect,\r\n            &#39;top&#39;\r\n        );\r\n    }\r\n\r\n    flush_rewrite_rules();\r\n}\r\nadd_action(&#39;init&#39;, &#39;custom_rewrite_rules&#39;);\r\n<\/code><\/pre>\r\n<p>\u3053\u308c\u306b\u3088\u308a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306aURL\u5909\u63db\u304c\u884c\u308f\u308c\u307e\u3059\uff1a<\/p>\r\n<ul style=\"list-style-type:bullet;\">\r\n<li><code>\/category\/cat-name-1\/<\/code> \u2192 <code>\/posts\/category1\/<\/code><\/li>\r\n<li><code>\/category\/cat-name-2\/<\/code> \u2192 <code>\/posts\/category2\/<\/code><\/li>\r\n<li><code>\/category\/cat-name-3\/<\/code> \u2192 <code>\/posts\/category3\/<\/code><\/li>\r\n<\/ul>\r\n<h2>\u30bf\u30a4\u30c8\u30eb\u306eHTML\u30bf\u30b0\u51e6\u7406<\/h2>\r\n<p>\u8a18\u4e8b\u30bf\u30a4\u30c8\u30eb\u306bHTML\u30bf\u30b0\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u5834\u5408\uff08\u4f8b\uff1a<code>&lt;br&gt;<\/code>\u30bf\u30b0\u306b\u3088\u308b\u6539\u884c\u306a\u3069\uff09\u3001\u30d1\u30f3\u304f\u305a\u30ea\u30b9\u30c8\u3067\u306f\u8868\u793a\u30921\u884c\u306b\u307e\u3068\u3081\u305f\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\r\n<p>\u305d\u306e\u3088\u3046\u306a\u5834\u5408\u306f<code>wp_strip_all_tags()<\/code>\u95a2\u6570\u3092\u4f7f\u7528\u3057\u307e\u3059\uff1a<\/p>\r\n<pre><code class=\"language-php\">echo wp_strip_all_tags(do_shortcode(&#39;WordPress\u306e\u30d1\u30f3\u304f\u305a\u30ea\u30b9\u30c8\u306e\u4f5c\u308a\u65b9\u3068\u30ab\u30b9\u30bf\u30de\u30a4\u30ba&#39;), false);\r\n<\/code><\/pre>\r\n<p>\u3053\u306e\u95a2\u6570\u306e\u7b2c2\u5f15\u6570\u306b\u3064\u3044\u3066\uff1a<\/p>\r\n<ul style=\"list-style-type:bullet;\">\r\n<li><code>true<\/code>: \u6539\u884c\u3092\u7a7a\u767d\u306b\u5909\u63db<\/li>\r\n<li><code>false<\/code>: \u6539\u884c\u3092\u305d\u306e\u307e\u307e\u4fdd\u6301<\/li>\r\n<\/ul>\r\n<p>\u901a\u5e38\u306e\u8a18\u4e8b\u30bf\u30a4\u30c8\u30eb\u3067\u306f\u5b9f\u969b\u306e\u6539\u884c\u6587\u5b57\uff08\\n\u3001\\r\u3001\\r\\n\uff09\u306f\u542b\u307e\u308c\u306a\u3044\u305f\u3081\u3001<code>false<\/code>\u3092\u6307\u5b9a\u3059\u308b\u3060\u3051\u3067\u5341\u5206\u3067\u3059\u3002<\/p>\r\n<h2>\u307e\u3068\u3081<\/h2>\r\n<ol style=\"list-style-type:decimal;\">\r\n<li>\u30d1\u30f3\u304f\u305a\u30ea\u30b9\u30c8\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u306e\u73fe\u5728\u4f4d\u7f6e\u3092\u793a\u3059\u91cd\u8981\u306a\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u8981\u7d20\u3067\u3059<\/li>\r\n<li>WordPress\u306e\u6761\u4ef6\u5206\u5c90\u30bf\u30b0\u3092\u4f7f\u7528\u3057\u3066\u3001\u9069\u5207\u306a\u968e\u5c64\u69cb\u9020\u3092\u8868\u73fe\u3067\u304d\u307e\u3059<\/li>\r\n<li>\u30ea\u30e9\u30a4\u30c8\u30eb\u30fc\u30eb\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001URL\u306e\u69cb\u9020\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3067\u304d\u307e\u3059<\/li>\r\n<li><code>wp_strip_all_tags()<\/code>\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30bf\u30a4\u30c8\u30eb\u306eHTML\u30bf\u30b0\u3092\u9069\u5207\u306b\u51e6\u7406\u3067\u304d\u307e\u3059<\/li>\r\n<\/ol>\r\n<p>\u30ea\u30e9\u30a4\u30c8\u30eb\u30fc\u30eb\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u3001\u30d1\u30fc\u30de\u30ea\u30f3\u30af\u8a2d\u5b9a\u306e\u66f4\u65b0\u304c\u5fc5\u8981\u306b\u306a\u308b\u3053\u3068\u304c\u3042\u308b\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\r\n","protected":false},"excerpt":{"rendered":"WordPress\u3067\u30d1\u30f3\u304f\u305a\u30ea\u30b9\u30c8\u3092\u5b9f\u88c5\u3059\u308b\u65b9\u6cd5\u3068\u3001\u30ea\u30f3\u30af\u5148\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002 \u57fa\u672c\u7684\u306a\u30d1\u30f3\u304f\u305a\u30ea\u30b9\u30c8\u306e\u5b9f\u88c5 \u307e\u305a\u3001breadcrumb.php\u3092\u4f5c\u6210\u3057\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u5b9f\u88c5\u3057\u307e\u3059\uff1a &lt;na[...]","protected":false},"author":1,"featured_media":7283,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","footnotes":"","vk-ltc-link":"","vk-ltc-target":"0"},"categories":[13],"tags":[85,84,86],"group":[],"pg":[],"class_list":["post-7227","post","type-post","status-publish","format-standard","has-post-thumbnail","category-wordpress","tag-85","tag-84","tag-86"],"acf":[],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/7227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/comments?post=7227"}],"version-history":[{"count":0,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/7227\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/media\/7283"}],"wp:attachment":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/media?parent=7227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/categories?post=7227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/tags?post=7227"},{"taxonomy":"group","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/group?post=7227"},{"taxonomy":"pg","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/pg?post=7227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}