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:
domain.com/blog/
<-- blog indexdomain.com/blog/politics/
<-- blog categorydomain.com/blog/politics/who-is-donald-trump
<-- blog postThe closest I am able to get is:
domain.com/blog/
<-- blog indexdomain.com/blog/category/politics/
<-- blog category (note the addition of the word "category")domain.com/blog/politics/who-is-donald-trump
<-- blog postFor 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.
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 );