1

I need any posts of any category (and archive pages) to route through /blog/. I added "blog" to my category base, but now both website.com/blog/my-category/ AND website.com/my-category/ both display the same content. Single posts redirect to website.com/my-category/my-post-name

I have Yoast installed, have gone back and forth trying their "remove category base" option, and nothing is working. It's deactivated now while I figure this out.

Any idea how to force category, archive, and single post pages to use the category base?

1

I found a solution here: 404 on category.php pagination

So, to fix my issue I just needed to add these custom rewrite rules to functions.php:

add_action( 'init', 'wpa58471_category_base' );
function wpa58471_category_base() {
    add_rewrite_rule(
        'blog/([^/]+)/page/(\d+)/?$',
        'index.php?category_name=$matches[1]&paged=$matches[2]',
        'top' 
    );
    add_rewrite_rule( 
        'blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$',
        'index.php?category_name=$matches[1]&feed=$matches[2]', 
        'top' 
    );
}

Now, all blog pages work, including main blog page, archives, categories, and single posts, using the permalink custom structure of /blog/%category/%postname%

**ALSO, if using Yoast, make sure you "Keep" the category base (this is the default under advanced->permalinks)

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.