Skip to content

Instantly share code, notes, and snippets.

@askaaqib
Last active August 20, 2020 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save askaaqib/55a858a5e9f058f982cf53eaf762e012 to your computer and use it in GitHub Desktop.
Save askaaqib/55a858a5e9f058f982cf53eaf762e012 to your computer and use it in GitHub Desktop.
WordPress Category Permastructure
<?php
function wpa85084_category_permastruct(){
global $wp_rewrite;
$wp_rewrite->extra_permastructs['category']['struct'] = '/blog/%category%/';
}
add_action( 'init', 'wpa85084_category_permastruct' );
add_action( 'init', 'wpa58471_category_base' );
function wpa58471_category_base() {
// Remember to flush the rules once manually after you added this code!
add_rewrite_rule(
// The regex to match the incoming URL
'blog/([^/]+)/([^/]+)/([^/]+)(/[0-9]+)?/?$',
// The resulting internal URL
'index.php?category_name=$matches[1]/$matches[2]&name=$matches[3]&paged=$matches[4]',
// Add the rule to the top of the rewrite list
'top' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment