wordpresspermalinks

Prefixing WordPress permalinks with blog and category name


I am really struggling with WordPress permalinks and wondering if what I'm trying to do is not possible.

I would like the following permalink structure:

The closest I am able to get is:

For my permalink structure I have it set to: /blog/%category%/%postname%/

And for my category prefix I have it set to: blog

This does actually generate the permalinks in the desired format, however the final posts page doesn't work, and returns a 404 error.


Solution

  • I finally got this working as follows:

    Permalink structure set to: /blog/%category%/%postname%/

    Category base set to: blog/. (note the period on the end)

    This was all fine but in my Yoast post sitemap the URL's contained a period, which was fixed with the following code placed in my theme's functions.php file:

    add_filter( 'category_link', function( $term_link, $term_id ) {
        $term_link = home_url('/blog/'. get_term( $term_id )->slug .'/');
        return $term_link; 
    }, 10, 2 );