Single Category Permalink


Reduce permalinks (category or post) that include entire hierarchy of categories to just having the lowest category in the hierarchy.

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:

  |_ Desktop
  |_ Web
    |_ WordPress

By default, if you have a permalink structure defined as %category%/%year%/%monthnum%/%day%/%postname%, your post titled “Best Plugins” assigned to the “WordPress” category would have a permalink of:

If you activate the Single Category Permalink plugin, this would be the permalink generated for the post (and recognized by the blog):

In order for a category to be used as part of a post’s permalink structure, %category% must be explicitly defined in the Settings -> Permalinks admin page as part of a custom structure, i.e. /%category%/%postname%.

For category links, %category% 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:

With this plugin activated, that link would become:

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.

Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage


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.

c2c_single_category_redirect_status (filter)

The ‘c2c_single_category_redirect_status’ hook allows you to specify an HTTP status code used for the redirect. By default this is 302.


  • $status (integer) : The default HTTP status code


 * Change the redirection HTTP status to a 302.
 * @param  int $code The HTTP status code. By default 301.
 * @return int
function scp_change_redirect_status( $code ) {
    return 302;
add_filter( 'c2c_single_category_redirect_status', 'scp_change_redirect_status' );


  1. Install via the built-in WordPress plugin installer. Or download and unzip inside the plugins directory for your site (typically wp-content/plugins/)
  2. Activate the plugin through the ‘Plugins’ admin menu in WordPress
  3. Use %category% as a permalink tag in the Settings -> Permalinks admin options page when defining a custom permalink structure


Will existing links to my site that used the full category hierarchy still work?

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.

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?

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.

What can this plugin do for me if I don’t use `%category%` in my custom permalink structure?

In addition to handling custom permalink structures (used to generate permalinks for posts) that contain %category%, 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.

Does this plugin include unit tests?



May 17, 2018
gives you full control of your category permalinks... Really great plugin, works well!
Read all 3 reviews

Contributors & Developers

“Single Category Permalink” is open source software. The following people have contributed to this plugin.



2.3 (2019-03-18)

  • New: Add file and move all but most recent changelog entries into it
  • New: Add inline documentation for hook
  • Change: Initialize plugin on ‘plugins_loaded’ action instead of on load
  • Change: Merge do_init() into init()
  • CHange: Cast return value of c2c_single_category_redirect_status filter as integer
  • Change: Split paragraph in’s “Support” section into two
  • Change: Note compatibility through WP 5.1+
  • Change: Update copyright date (2019)
  • Change: Update License URI to be HTTPS

2.2.1 (2018-07-21)

  • Change: Switch away from using deprecated c2c_single_category_catlink() internally
  • Change: Move @uses DockBlock entries to get_http_redirect_status()
  • New: Unit tests: Add create_hierarchical_categories() for creating hierarchical categories so the behavior isn’t duplicated in a number of tests
  • New: Add
  • New: Add GitHub link to readme
  • Change: Minor whitespace tweaks to unit test bootstrap
  • Change: Note compatibility through WP 4.9+
  • Change: Rename readme.txt section from ‘Filters’ to ‘Hooks’
  • Change: Modify formatting of hook name in readme to prevent being uppercased when shown in the Plugin Directory
  • Change: Improve installation instructions
  • Change: Minor readme.txt tweaks
  • Change: Update copyright date (2018)

2.2 (2017-02-10)

  • Fix: Replace use of deprecated (in WP 4.7) _usort_terms_by_ID() with wp_list_sort() for WP 4.7+.
  • Change: Change default redirect HTTP status code from 302 (temporary redirect) to 301 (permanent redirect).
  • Change: Wrap functionality in class.
    • Create class c2c_SingleCategoryPermalink
    • Deprecate existing functions: c2c_single_category_catlink(), c2c_single_category_postlink(), c2c_single_category_redirect()
    • Move deprecated function functionality to class methods: category_link(), post_link(), template_redirect()
    • Add method version() to return plugin version
  • Add get_http_redirect_status() for getting the HTTP status code for redirects.
  • Change: Default WP_TESTS_DIR to /tmp/wordpress-tests-lib rather than erroring out if not defined via environment variable.
  • Change: Enable more error output for unit tests.
  • Change: Note compatibility through WP 4.7+.
  • Change: Remove support for WordPress older than 4.6 (should still work for earlier versions back to WP 1.5)
  • Change: Update copyright date (2017).

Full changelog is available in