WordPress / Web Development Tutorials
(Best WordPress Tutorials)

CSSHTMLJavaScriptjQueryMySQLPHPSilvaTechnologiesWooCommerceWordpress
Silva Web Designs - Blog

How to add /blog/ in front of your single post URLs in WordPress

Today we will show you how to add /blog/ in front of your single post URL’s. Let’s take this blog post for example, at the moment you will see the single post is the default ‘how-to-add-blog-in-front-of-your-single-post-urls-in-wordpress’, maybe you or one of your clients has asked you to change this to ‘/blog/how-to-add-blog-in-front-of-your-single-post-urls-in-wordpress’. This can be achieved quite easily.

Adding ‘blog’ to your single posts

Firstly, you will want to go to your Permalinks settings (WP Admin → Settings → Permalinks) and select ‘Custom Structure’. It should display your current structure in the text box next to it. Now, add /blog in front of what is in the text box (including the slash in front!). You can change the word blog if you want something different.

Adding /blog/ to your categories and tags

Next, we’ll also add the new base in front of the category and tag URLs. If the text boxes are empty, add this in the Category base: blog/category and this in the Tag base: blog/tag;

And that’s it. Your blogs will now have blog/ in front of them whilst your other pages remain unchanged!

Custom post types

If you are using Custom Post Types (CPT) on your site, you will need to make sure that ‘rewrite with front’ is disabled for each of your post types. Otherwise your custom post type URLs will also get changed to have /blog in-front of them.

If you use a plugin to register your CPT’s, look for the ‘Rewrite‘ option, and make sure that ‘With Front‘ is unchecked. After saving your settings, go back to the Permalinks Settings and click ‘Save Changes’ (this is necessary so that the new links are re-generated).

If this doesn’t work, try also filling out the ‘Slug’ in your post type ‘Rewrite’ settings. Some plugins require this for the ‘With Front’ option to work (and again, save your permalink settings!).

If you have created your own CPT’s in your code, make sure that when registering your post type, you have disabled rewrite with front. As an example, if you had a CPT for Events you will need to add the following code:


'rewrite'	      	=> array( 
	'slug' => 'events',
	'with_front' => false
),

As always, after making this change, save your permalink settings in WP Admin after changing your rewrite rules!

We hope you found this useful… happy coding!

 

Nathan da Silva - Profile

Posted by: Nathan da Silva

Nathan is the Founder of Silva Web Designs. He is passionate about web development, website design and basically anything digital-related. His main expertise is with WordPress and various other CMS frameworks. If you need responsive design, SEO, speed optimisation or anything else in the world of digital, you can contact Silva Web Designs here; [email protected]

It’s good to share

10 thoughts on “How to add /blog/ in front of your single post URLs in WordPress

  1. Thanks for the helpful article.
    But how to make it so that the slug is added only to the links of posts, and not to the link to the author’s page.
    Now the link to the author’s page looks like this SITE_URL/blog/author/admin/

  2. How can i remove the “category” slug from the category urls? When I use “blog” only for the category base I get 404errors :-/

    1. If you want to remove /category/ from the URL, do the following:

      1. Go to Settings >> Permalinks and select Custom and enter: /%category%/%postname%/
      Next set your Category Base to .

      Save it and you’ll see your URL format will change to what you are looking for.

  3. Hi

    Thank you for the article and the time you’ve given to it.

    The second part of your article, removing /blog/ from Custom Post Types doesn”t seem to be working (any more?). I have set with_front to false but I still have blog in the URL

    Any ideas?

  4. This works as described especially the rewrite part, that’s the part that not many tutorials talk abot and that’s where I needed insight. Thanks again!

Join the discussion