2

I changed http://domain.com/%postname%/ to http://domain.com/news/%postname%/ using the answer provided here: Add a URL prefix to permalinks of one category of posts only. But I am having issues with categories under NEWS itself. How can I make this work for sub-categories

  • For complex modifications to URL strictures you'll likely need to amend WordPress' rewrite rules. In order to help anyone answering you should post an example of the URL structure you would ideally have. – Chris Morris Jan 19 '18 at 9:54
0
add_action( 'init', 'wpa_category_base' );
function wpa_category_base() {
    // Remember to flush the rules once manually after you added this code!
    add_rewrite_rule(
        // The regex to match the incoming URL
        'news/([^/]+)/([^/]+)/([^/]+)(/[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' );
}

Custom permalink structure: /media/%category%/%postname%/ Category base: .

Worked for me, WordPress 3.4.1, without any related plugins.

Try

add_action( 'init', 'wpa_category_base' );
function wp_category_base() {
// Remember to flush the rules once manually after you added this code!
    add_rewrite_rule(
    // The regex to match the incoming URL
    'news/([^/]+)/([^/]+)/([^/][^f][^e][^e][^d]+)(/[0-9]+)?/?$', //here my changes to exclude 'feed'
    // 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' );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.