{"id":5705,"date":"2011-07-18T06:42:00","date_gmt":"2011-07-18T06:42:00","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/single-category-permalink\/"},"modified":"2021-09-29T07:28:01","modified_gmt":"2021-09-29T07:28:01","slug":"single-category-permalink","status":"publish","type":"plugin","link":"https:\/\/pirate.wordpress.org\/plugins\/single-category-permalink\/","author":3606,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"2.5.2","stable_tag":"2.5.2","tested":"5.8.13","requires":"4.6","requires_php":"","requires_plugins":"","header_name":"Single Category Permalink","header_author":"Scott Reilly","header_description":"","assets_banners_color":"0074a2","last_updated":"2021-09-29 07:28:01","external_support_url":"","external_repository_url":"","donate_link":"https:\/\/www.paypal.com\/cgi-bin\/webscr?cmd=_s-xclick&hosted_button_id=6ARCFJ9TX3522","header_plugin_uri":"https:\/\/coffee2code.com\/wp-plugins\/single-category-permalink\/","header_author_uri":"https:\/\/coffee2code.com\/","rating":5,"author_block_rating":0,"active_installs":400,"downloads":27905,"num_ratings":5,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","faq","changelog"],"tags":{"2.0":{"tag":"2.0","author":"coffee2code","date":"2011-07-18 06:42:00"},"2.0.1":{"tag":"2.0.1","author":"coffee2code","date":"2011-07-22 01:22:37"},"2.0.2":{"tag":"2.0.2","author":"coffee2code","date":"2011-12-22 04:24:51"},"2.0.3":{"tag":"2.0.3","author":"coffee2code","date":"2012-06-04 17:56:18"},"2.0.4":{"tag":"2.0.4","author":"coffee2code","date":"2012-12-16 07:43:09"},"2.1":{"tag":"2.1","author":"coffee2code","date":"2014-01-25 08:03:38"},"2.1.1":{"tag":"2.1.1","author":"coffee2code","date":"2015-02-17 20:49:13"},"2.2":{"tag":"2.2","author":"coffee2code","date":"2017-02-25 17:38:02"},"2.3":{"tag":"2.3","author":"coffee2code","date":"2019-03-18 20:16:43"},"2.4":{"tag":"2.4","author":"coffee2code","date":"2020-01-18 06:38:12"},"2.4.1":{"tag":"2.4.1","author":"coffee2code","date":"2020-01-19 08:16:53"},"2.4.2":{"tag":"2.4.2","author":"coffee2code","date":"2020-06-02 07:12:17"},"2.5":{"tag":"2.5","author":"coffee2code","date":"2020-09-27 07:18:09"},"2.5.1":{"tag":"2.5.1","author":"coffee2code","date":"2021-05-01 05:56:29"},"2.5.2":{"tag":"2.5.2","author":"coffee2code","date":"2021-09-29 07:28:01"}},"upgrade_notice":{"2.5.2":"<p>Trivial update: noted compatibility through WP 5.8+ and minor reorganization and tweaks to unit tests<\/p>","2.5.1":"<p>Trivial update: noted compatibility through WP 5.7+ and updated copyright date (2021).<\/p>","2.5":"<p>Minor update: Minor compatibility updates, restructured unit test file structure, expanded unit test coverage, and noted compatibility through WP 5.5+.<\/p>","2.4.2":"<p>Trivial update: Updated a few URLs to be HTTPS and noted compatibility through WP 5.4+<\/p>","2.4.1":"<p>Recommended bugfix release: prevented interfering with permalinks for non-category taxonomies<\/p>","2.4":"<p>Minor update: modernized unit tests, noted compatibility through WP 5.3+, added TODO.md, and updated copyright date (2020)<\/p>","2.3":"<p>Minor update: tweaked plugin initialization process, created CHANGELOG.md to store historical changelog outside of readme.txt, noted compatibility through WP 5.1+, updated copyright date (2019)<\/p>","2.2.1":"<p>Trivial update: minor documentation and code formatting tweaks, noted compatibility through WP 4.9+, and updated copyright date (2018)<\/p>","2.2":"<p>Recommended update: changed default HTTP redirect status code to 301 (permanent), fixed PHP warning in WP 4.7 due to function deprecation, restructured code, compatibility is now WP 4.6-4.7+, added more unit tests, updated copyright date, more<\/p>","2.1.2":"<p>Trivial update: verified compatibility through WP 4.5; updated copyright date (2016).<\/p>","2.1.1":"<p>Trivial update: noted compatibility through WP 4.1+; updated copyright date (2015); added plugin icon<\/p>","2.1":"<p>Minor update: added unit tests; noted compatibility through WP 3.8+<\/p>","2.0.4":"<p>Trivial update: noted compatibility through WP 3.5+<\/p>","2.0.3":"<p>Trivial update: noted compatibility through WP 3.4+; explicitly stated license<\/p>","2.0.2":"<p>Trivial update: noted compatibility through WP 3.3+<\/p>","2.0.1":"<p>Bugfix release: fixed bug triggered when creating new post (especially recommended if using %category% in custom permalink structure)<\/p>","2.0":"<p>Recommended update. No functional changes, but many changes to formatting and documentation; noted compatibility through WP 3.2.<\/p>"},"ratings":{"1":0,"2":0,"3":0,"4":0,"5":"5"},"assets_icons":{"icon-128x128.png":{"filename":"icon-128x128.png","revision":1092767,"resolution":"128x128","location":"assets","locale":""}},"assets_banners":{"banner-772x250.png":{"filename":"banner-772x250.png","revision":845064,"resolution":"772x250","location":"assets","locale":""}},"assets_blueprints":{},"all_blocks":[],"tagged_versions":["2.0","2.0.1","2.0.2","2.0.3","2.0.4","2.1","2.1.1","2.2","2.3","2.4","2.4.1","2.4.2","2.5","2.5.1","2.5.2"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[89,2758,537,2662,8712],"plugin_category":[],"plugin_contributors":[78189],"plugin_business_model":[],"class_list":["post-5705","plugin","type-plugin","status-publish","hentry","plugin_tags-category","plugin_tags-coffee2code","plugin_tags-link","plugin_tags-permalink","plugin_tags-structure","plugin_contributors-coffee2code","plugin_committers-coffee2code"],"banners":{"banner":"https:\/\/ps.w.org\/single-category-permalink\/assets\/banner-772x250.png?rev=845064","banner_2x":false,"banner_rtl":false,"banner_2x_rtl":false},"icons":{"svg":false,"icon":"https:\/\/ps.w.org\/single-category-permalink\/assets\/icon-128x128.png?rev=1092767","icon_2x":false,"generated":false},"screenshots":[],"raw_content":"<!--section=description-->\n<p>Reduce permalinks (category or post) that include entire hierarchy of categories to just having the lowest category in the hierarchy.<\/p>\n\n<p>By default, WordPress replaces the %category% permalink tag in a custom permalink structure with the entire hierarchy of categories for the post's first matching category. For example, assuming your site has a hierarchical category structure like so:<\/p>\n\n<pre><code>Applications\n  |_ Desktop\n  |_ Web\n    |_ WordPress\n<\/code><\/pre>\n\n<p>By default, if you have a permalink structure defined as <code>%category%\/%year%\/%monthnum%\/%day%\/%postname%<\/code>, your post titled \"Best Plugins\" assigned to the \"WordPress\" category would have a permalink of:<\/p>\n\n<pre><code>https:\/\/www.example.com\/applications\/web\/wordpress\/2008\/01\/15\/best-plugins\n<\/code><\/pre>\n\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\n<pre><code>https:\/\/www.example.com\/wordpress\/2008\/01\/15\/best-plugins\n<\/code><\/pre>\n\n<p>In order for a category to be used as part of a post's permalink structure, <code>%category%<\/code> must be explicitly defined in the Settings -&gt; Permalinks admin page as part of a custom structure, i.e. <code>\/%category%\/%postname%<\/code>.<\/p>\n\n<p>For category links, <code>%category%<\/code> is implied to follow the value set as the \"Category base\" (or the default category base if none is specified). So if your category base is 'category', the above example would list posts in the 'WordPress' category on this category listing page:<\/p>\n\n<pre><code>https:\/\/www.example.com\/category\/applications\/web\/wordpress\/\n<\/code><\/pre>\n\n<p>With this plugin activated, that link would become:<\/p>\n\n<pre><code>https:\/\/www.example.com\/category\/wordpress\/\n<\/code><\/pre>\n\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\n<p>Links: <a href=\"https:\/\/coffee2code.com\/wp-plugins\/single-category-permalink\/\">Plugin Homepage<\/a> | <a href=\"https:\/\/wordpress.org\/plugins\/single-category-permalink\/\">Plugin Directory Page<\/a> | <a href=\"https:\/\/github.com\/coffee2code\/single-category-permalink\/\">GitHub<\/a> | <a href=\"https:\/\/coffee2code.com\">Author Homepage<\/a><\/p>\n\n<h3>Hooks<\/h3>\n\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's functions.php file.<\/p>\n\n<p><strong>c2c_single_category_redirect_status (filter)<\/strong><\/p>\n\n<p>The 'c2c_single_category_redirect_status' hook allows you to specify an HTTP status code used for the redirect. By default this is 302.<\/p>\n\n<p>Arguments:<\/p>\n\n<ul>\n<li>$status (integer) : The default HTTP status code<\/li>\n<\/ul>\n\n<p>Example:<\/p>\n\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\n<!--section=installation-->\n<ol>\n<li>Install via the built-in WordPress plugin installer. Or download and unzip <code>single-category-permalinks.zip<\/code> inside the plugins directory for your site (typically <code>wp-content\/plugins\/<\/code>)<\/li>\n<li>Activate the plugin through the 'Plugins' admin menu in WordPress<\/li>\n<li>Use <code>%category%<\/code> as a permalink tag in the <code>Settings<\/code> -&gt; <code>Permalinks<\/code> admin options page when defining a custom permalink structure<\/li>\n<\/ol>\n\n<!--section=faq-->\n<dl>\n<dt id='will%20existing%20links%20to%20my%20site%20that%20used%20the%20full%20category%20hierarchy%20still%20work%3F'><h3>Will existing links to my site that used the full category hierarchy still work?<\/h3><\/dt>\n<dd><p>Yes, WordPress will still serve the category listings and posts regardless of whether it is of the full category hierarchy format or just the single category format. But do note that WordPress doesn't perform any sort of redirects; it responds directly to the category\/post URL requested.<\/p><\/dd>\n<dt id='could%20this%20give%20the%20appearance%20that%20i%20have%20duplicate%20content%20on%20my%20site%20if%20pages%20are%20accessible%20via%20the%20full%20category%20hierarchy%20permalink%20format%20and%20the%20single%20category%20permalink%20format%3F'><h3>Could this give the appearance that I have duplicate content on my site if pages are accessible via the full category hierarchy permalink format and the single category permalink format?<\/h3><\/dt>\n<dd><p>Whether this plugin is active or not, WordPress treats both types of category links the same. This plugin will however issue redirects for all of the non-canonical category and post permalink pages to point to the single category link version.<\/p><\/dd>\n<dt id='what%20can%20this%20plugin%20do%20for%20me%20if%20i%20don%27t%20use%20%60%25category%25%60%20in%20my%20custom%20permalink%20structure%3F'><h3>What can this plugin do for me if I don't use `%category%` in my custom permalink structure?<\/h3><\/dt>\n<dd><p>In addition to handling custom permalink structures (used to generate permalinks for posts) that contain <code>%category%<\/code>, the plugin also shortens category archive links. WordPress by default generates those links in a fully hierarchical fashion which this plugin will reduce to a single category. See the Description section for an example.<\/p><\/dd>\n<dt id='does%20this%20plugin%20include%20unit%20tests%3F'><h3>Does this plugin include unit tests?<\/h3><\/dt>\n<dd><p>Yes.<\/p><\/dd>\n\n<\/dl>\n\n<!--section=changelog-->\n<h4>2.5.2 (2021-09-28)<\/h4>\n\n<ul>\n<li>Change: Note compatibility through WP 5.8+<\/li>\n<li>Unit tests:\n\n<ul>\n<li>Change: Restructure unit test directories\n\n<ul>\n<li>Change: Move <code>phpunit\/bin\/<\/code> into <code>tests\/<\/code><\/li>\n<li>Change: Move <code>phpunit\/<\/code> into <code>tests\/<\/code><\/li>\n<\/ul><\/li>\n<li>Change: Remove 'test-' prefix from unit test file<\/li>\n<li>Change: In bootstrap, store path to plugin file constant<\/li>\n<li>Change: In bootstrap, add backcompat for PHPUnit pre-v6.0<\/li>\n<\/ul><\/li>\n<\/ul>\n\n<h4>2.5.1 (2021-04-30)<\/h4>\n\n<ul>\n<li>Change: Note compatibility through WP 5.7+<\/li>\n<li>Change: Update copyright date (2021)<\/li>\n<\/ul>\n\n<h4>2.5 (2020-09-23)<\/h4>\n\n<ul>\n<li>Fix: Default the <code>$taxonomy<\/code> argument of <code>category_link()<\/code> to 'category' to avoid a PHP warning\/error<\/li>\n<li>Fix: Handle the possibility that <code>get_category()<\/code> could return <code>null<\/code> for an invalid category ID<\/li>\n<li>New: Add a TODO item about removing deprecated functions (which is not something I want to do just yet, hence the TODO)<\/li>\n<li>Change: Update docs for return value of <code>category_link()<\/code> to reflect that <code>WP_Error<\/code> or <code>null<\/code> are also possible values<\/li>\n<li>Change: Note compatibility through WP 5.5+<\/li>\n<li>Change: Restructure unit test file structure\n\n<ul>\n<li>New: Create new subdirectory <code>phpunit\/<\/code> to house all files related to unit testing<\/li>\n<li>Change: Move <code>bin\/<\/code> to <code>phpunit\/bin\/<\/code><\/li>\n<li>Change: Move <code>tests\/bootstrap.php<\/code> to <code>phpunit\/<\/code><\/li>\n<li>Change: Move <code>tests\/<\/code> to <code>phpunit\/tests\/<\/code><\/li>\n<li>Change: Rename <code>phpunit.xml<\/code> to <code>phpunit.xml.dist<\/code> per best practices<\/li>\n<\/ul><\/li>\n<li>Unit tests:\n\n<ul>\n<li>New: Add tests for <code>category_link()<\/code>, <code>post_link()<\/code><\/li>\n<li>New: Add <code>unset_permalink_structures()<\/code> to unset configured permalink structures<\/li>\n<\/ul><\/li>\n<\/ul>\n\n<p><em>Full changelog is available in <a href=\"https:\/\/github.com\/coffee2code\/single-category-permalink\/blob\/master\/CHANGELOG.md\">CHANGELOG.md<\/a>.<\/em><\/p>","raw_excerpt":"Reduce permalinks (category or post) that include entire hierarchy of categories to just having the lowest level category.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/5705","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"author":[{"embeddable":true,"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/users\/3606"}],"replies":[{"embeddable":true,"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=5705"}],"wp:attachment":[{"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=5705"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=5705"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=5705"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=5705"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=5705"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/pirate.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=5705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}