How to add /blog/ as a prefix to permalink structure for blog posts in WordPress

Here is a snippet on how to turn all of your posts to new permalink structure without affecting other post types.
In this example I changed all my posts to have /blog/ in url.

This snippet should be added somewhere in your functions.php file.

Possible problems

You might bump into a problem with ‘Redirect loop’ after you add this code.
If you encounter that problem, just delete all from L31 > L45.

After adding these functions if you don’t do a redirect form ‘old url’ > ‘new url’, your posts will be accessible on both url’s, and from SEO point of view this is not good for you.
1. Duplicate content issue
2. There might be some links out there pointing back to your posts, and this is why you shoud 301 redirect them to new location.


    1. Hi Sallie,
      Try just changing your permalinks under settings > permalinks. It might work with any of these too.

Leave a Reply

Your email address will not be published. Required fields are marked *