Tag Archives: categories

Change Sub Category to Main Category URL Structure (WordPress Remove Sub Category Hierarchy URL)

While working on Enjfi, I ran into an undesired feature. When browsing to a sub-category, in WordPress, I ended up with a URL structure like:




Now, that usually works. But, with Enjifi, I may want to move sub-category under category-2, like:




Now, all my links to /category/sub-category are not /category-2/sub-category, the undesired feature.

So, I found this, and I wrote a plugin for it (because it worked).


[php wraplines=”true”]

Plugin Name: Change Sub Category to Main Category URL Structure (WordPress Remove Sub Category Hierarchy URL)
Plugin URI: https://devblog.aubreypwd.com/
Description: This plugin will tell your website to remap /category/category/subcategory to /category/subcategory
Version: 0.1
Author: Aubrey Island
Author Email: enethrie@gmail.com
Author URI: https://devblog.aubreypwd.com

/* From: http://wordpress.stackexchange.com/questions/7807/changing-the-category-permalink-structure/7817#7817 */

add_filter( ‘category_link’, ‘wpse7807_category_link’, 10, 2 );
function wpse7807_category_link( $catlink, $category_id )
global $wp_rewrite;
$catlink = $wp_rewrite->get_category_permastruct();

if ( empty( $catlink ) ) {
$catlink = home_url(‘?cat=’ . $category_id);
} else {
$category = &get_category( $category_id );
$category_nicename = $category->slug;

$catlink = str_replace( ‘%category%’, $category_nicename, $catlink );
$catlink = home_url( user_trailingslashit( $catlink, ‘category’ ) );
return $catlink;



Allow HTML in your Category Descriptions in WordPress

So, while I was actually starting to move posts over to this lovely site, I noticed that when I saved a category’s description, certain HTML was being stripped.

For example (please no comments on quotes, this is HTML5!),

[html wraplines=”true”]
<a href=http://www.vim.org/ target=_blank>Vim</a> is an editor that I came across when looking for alternatives to, what I was currently using, <a href=http://notepad-plus-plus.org></a>Notepad++. I eventually started customizing it and trying to get it to work for me. At one point I even gave up, but came back to give it a try again.

It eventually lead to <a href=https://devblog.aubreypwd.com/category/vim/aubreys-gvim></a>Aubrey’s gVim, as well as <a href=/tag/vimtips>vimTips</a> and <a href=/tag/aubreygvimtips>Aubrey’s gVim Tips</a>.

In this piece of code, inside a category description, though links were allowed, the class=it was not!

This plugin really came in handy!

[Allow HTML in Category Descriptions]