{"id":962,"date":"2025-03-24T14:28:08","date_gmt":"2025-03-24T14:28:08","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/how-to-add-parent-slug-to-cpt-url\/"},"modified":"2025-04-03T15:24:29","modified_gmt":"2025-04-03T14:24:29","slug":"how-to-add-parent-slug-to-cpt-url","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/code-snippets\/how-to-add-parent-slug-to-cpt-url\/","title":{"rendered":"How to add parent slug to CPT URL"},"content":{"rendered":"\n<p>If you need to add a second root parent slug to your Custom Post Type, you can do it using the below <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/useful-plugins\/code-snippets-plugin\/\">code snippet<\/a>.<br><br>This will add the word &#8220;resources&#8221; to the URL so &#8220;\/places\/&#8221; will become &#8220;\/resources\/places\/&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">function gd_snippet_option_post_types( $value, $key, $default ) {\n\t$post_type \t= &#039;gd_place&#039;; \/\/ Post type\n\t$top_level_item = &#039;resources&#039;; \/\/ Top level item\n\n\tif ( ! empty( $value&#091; $post_type &#093; ) ) {\n\t\t$value&#091; $post_type &#093;&#091;&#039;has_archive&#039;&#093; \t= $top_level_item . &#039;\/&#039; . $value&#091; $post_type &#093;&#091;&#039;rewrite&#039;&#093;&#091;&#039;slug&#039;&#093;;\n\t\t$value&#091; $post_type &#093;&#091;&#039;rewrite&#039;&#093;&#091;&#039;slug&#039;&#093; = $top_level_item . &#039;\/&#039; . $value&#091; $post_type &#093;&#091;&#039;rewrite&#039;&#093;&#091;&#039;slug&#039;&#093;;\n\t}\n\n\treturn $value;\n}\nadd_filter( &#039;geodir_get_option_post_types&#039;, &#039;gd_snippet_option_post_types&#039;, 21, 3 );<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you need to add a second root parent slug to your Custom Post Type, you can do it using the below code snippet. This will add the word &#8220;resources&#8221; to the URL so &#8220;\/places\/&#8221; will become &#8220;\/resources\/places\/&#8221;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[211,433],"class_list":["post-962","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-tips-tricks-more","gd_placecategory-code-snippets"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/962","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/comments?post=962"}],"version-history":[{"count":0,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/962\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=962"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=962"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}