Single Category Permalink
- Author:Scott Reilly
- Version:2.0.2
- Last update:2011-12-22
- Compatibility:WP 1.5 – 3.3.2
- Comments:go here
- Download:[ zip ]
- Description:
Reduce permalinks (category or post) that include entire hierarchy of categories to just having the lowest category in the hierarchy.
-
Extended Description
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:
Applications |_ Desktop |_ Web |_ WordPressBy 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:www.yourblog.com/applications/web/wordpress/2008/01/15/best-pluginsIf you activate the Single Category Permalink plugin, this would be the permalink generated for the post (and recognized by the blog):
www.yourblog.com/wordpress/2008/01/15/best-pluginsIn 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’ on this category listing page:www.yourblog.com/category/applications/web/wordpress/With this plugin activated, that link would become:
www.yourblog.com/category/wordpress/NOTE: The fully hierarchical category and post permalinks will continue to work. The plugin issues are 302 redirect to browsers and search engines pointing them to the shorter URL.
Links: Plugin Homepage | Plugin Directory Page | Author Homepage
Find out more at the plugin’s WordPress Plugin Repository page.
Installation
- Unzip
single-category-permalink.zipinside the/wp-content/plugins/directory for your site (or install via the built-in WordPress plugin installer) - Activate the plugin through the ‘Plugins’ admin menu in WordPress
- Use
%category%as a permalink tag in theSettings->Permalinksadmin options page when defining a custom permalink structure
- Unzip
-
Filters
The plugin exposes one filter for hooking. Typically, customizations utilizing this hook would be put into your active theme’s functions.php file, or used by another plugin.
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.
Arguments:
- $status (integer) : The default HTTP status code
Example:
// Change single category redirect to 301 function scp_change_redirect_status( $code ) { return 301; } add_filter( 'c2c_single_category_redirect_status', 'scp_change_redirect_status' );
Frequently Asked Questions
Q. Will existing links to my site that used the full category hierarchy still work?
A. 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.Q. 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?
A. 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.Q. What can this plugin do for me if I don’t use `%category%` in my custom permalink structure?
A. 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.
Release Log
2.0.2
- Note compatibility through WP 3.3+
- Add link to plugin directory page to readme.txt
- Update copyright date (2012)
2.0.1
- Fix bug triggered when creating new post
2.0
- Fix compatibility bug relating to generation of category permalink
- Rename single_category_postlink() to c2c_single_category_postlink()
- Rename single_category_catlink() to c2c_single_category_catlink()
- Add c2c_single_category_redirect() to redirect hierarchical category links to the single category alternative
- Add filter ‘c2c_single_category_redirect_status’ to allow override of default redirect status code
- Wrap all functions in if (!function_exists()) check
- Remove docs from top of plugin file (all that and more are in readme.txt)
- Add plugin homepage and author links in description in readme.txt
- Note compatibility through WP3.2+
- Add PHPDoc documentation
- Expand documentation in readme.txt
- Minor tweaks to code formatting (spacing)
- Minor documentation reformatting in readme.txt
- Change description
- Add package info to top of plugin file
- Add Frequently Asked Questions, Filters, Changelog, and Upgrade Notice sections to readme.txt
- Update copyright date (2011)
1.0
- Initial release
Copyright & Disclaimer
Copyright © 2011 by Scott Reilly (aka coffee2code)Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
