{"id":159941,"date":"2011-07-18T08:00:00","date_gmt":"2011-07-18T08:00:00","guid":{"rendered":"https:\/\/www.weixiaoduo.com\/plugins\/2024\/02\/22\/single-category-permalink\/"},"modified":"2021-09-29T15:28:00","modified_gmt":"2021-09-29T15:28:00","slug":"single-category-permalink","status":"publish","type":"post","link":"https:\/\/www.weixiaoduo.com\/plugins\/single-category-permalink\/","title":{"rendered":"Single Category Permalink"},"content":{"rendered":"<p>Reduce permalinks (category or post) that include entire hierarchy of categories to just having the lowest category in the hierarchy.<\/p>\n<p>By default, WordPress replaces the %category% permalink tag in a custom permalink structure with the entire hierarchy of categories for the post\u2019s first matching category. For example, assuming your site has a hierarchical category structure like so:<\/p>\n<pre><code>Applications\n  |_ Desktop\n  |_ Web\n    |_ WordPress\n<\/code><\/pre>\n<p>By default, if you have a permalink structure defined as <code>%category%\/%year%\/%monthnum%\/%day%\/%postname%<\/code>, your post titled \u201cBest Plugins\u201d assigned to the \u201cWordPress\u201d category would have a permalink of:<\/p>\n<pre><code>https:\/\/www.example.com\/applications\/web\/wordpress\/2008\/01\/15\/best-plugins\n<\/code><\/pre>\n<p>If you activate the Single Category Permalink plugin, this would be the permalink generated for the post (and recognized by the blog):<\/p>\n<pre><code>https:\/\/www.example.com\/wordpress\/2008\/01\/15\/best-plugins\n<\/code><\/pre>\n<p>In order for a category to be used as part of a post\u2019s permalink structure, <code>%category%<\/code> must be explicitly defined in the Settings -> Permalinks admin page as part of a custom structure, i.e. <code>\/%category%\/%postname%<\/code>.<\/p>\n<p>For category links, <code>%category%<\/code> is implied to follow the value set as the \u201cCategory base\u201d (or the default category base if none is specified). So if your category base is \u2018category\u2019, the above example would list posts in the \u2018WordPress\u2019 category on this category listing page:<\/p>\n<pre><code>https:\/\/www.example.com\/category\/applications\/web\/wordpress\/\n<\/code><\/pre>\n<p>With this plugin activated, that link would become:<\/p>\n<pre><code>https:\/\/www.example.com\/category\/wordpress\/\n<\/code><\/pre>\n<p>NOTE: The fully hierarchical category and post permalinks will continue to work. The plugin issues a 302 redirect to browsers and search engines pointing them to the shorter URL.<\/p>\n<p>Links: <a href=\"https:\/\/coffee2code.com\/wp-plugins\/single-category-permalink\/\" rel=\"nofollow ugc\">Plugin Homepage<\/a> | <a href=\"https:\/\/wordpress.org\/plugins\/single-category-permalink\/\" rel=\"ugc\">Plugin Directory Page<\/a> | <a href=\"https:\/\/github.com\/coffee2code\/single-category-permalink\/\" rel=\"nofollow ugc\">GitHub<\/a> | <a href=\"https:\/\/coffee2code.com\" rel=\"nofollow ugc\">Author Homepage<\/a><\/p>\n<h3>Hooks<\/h3>\n<p>The plugin exposes one filter for hooking. Code using this filter should ideally be put into a mu-plugin or site-specific plugin (which is beyond the scope of this readme to explain). Less ideally, you could put them in your active theme\u2019s functions.php file.<\/p>\n<p><strong>c2c_single_category_redirect_status (filter)<\/strong><\/p>\n<p>The \u2018c2c_single_category_redirect_status\u2019 hook allows you to specify an HTTP status code used for the redirect. By default this is 302.<\/p>\n<p>Arguments:<\/p>\n<ul>\n<li>$status (integer) : The default HTTP status code<\/li>\n<\/ul>\n<p>Example:<\/p>\n<pre><code>\/**\n * Change the redirection HTTP status to a 302.\n *\n * @param  int $code The HTTP status code. By default 301.\n * @return int\n *\/\nfunction scp_change_redirect_status( $code ) {\n    return 302;\n}\nadd_filter( 'c2c_single_category_redirect_status', 'scp_change_redirect_status' );\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Reduce permalinks (category or post) that include entire hierarchy of categories to just having the lowest level category.<\/p>\n","protected":false},"author":65,"featured_media":345303,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Single Category Permalink - \u8587\u6653\u6735\u63d2\u4ef6\u76ee\u5f55","description":"Reduce permalinks (category or post) that include entire hierarchy of categories to just having the lowest level category."},"footnotes":""},"categories":[1],"tags":[11,2605,635,1425,41644],"class_list":["post-159941","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-category","tag-coffee2code","tag-link","tag-permalink","tag-structure"],"_links":{"self":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/159941","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/comments?post=159941"}],"version-history":[{"count":0,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/159941\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media\/345303"}],"wp:attachment":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media?parent=159941"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/categories?post=159941"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/tags?post=159941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}