Last active
August 20, 2020 15:54
-
-
Save askaaqib/55a858a5e9f058f982cf53eaf762e012 to your computer and use it in GitHub Desktop.
WordPress Category Permastructure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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