How to add ‘/blog/’ in front of your URL

Let’s say you have your site running with WordPress, which is very likely now that WordPress runs 25% of the web. But along with your site you also have a blog and want to use a separete URL, something like: www.yoursite.com/blog/ and you want your posts to be something like www.yoursite.com/blog/my-post/.

Lucky for you, WordPress can add ‘blog’ to your links.

This is the aprouch we use here in Quema Labs, all our posts are prefixed with the word /blog/ and I want to show you how to do that.

First, go to your Permalinks settings in your Admin Panel > Settings > Permalinks, on Custom Structure you will see something like this:

Captura de pantalla 2015-11-24 a las 10.08.11

So let’s add at the begining the word ‘/blog‘, it will look like this:

Captura de pantalla 2015-11-24 a las 10.09.20

That will prefix all your blog posts with ‘/blog/’ but now we also want the categories and tags URLs working the same, so take a loox at the boxes below, probably they are empty, so let’s fill them with:

blog/category

blog/tag

This time you don’t have to add a slash at the begining:

Captura de pantalla 2015-11-24 a las 10.19.52

Now click Save Change and that’s it!.

 

Custom Post Type

If you are using Custom Post Type, they will also have that ‘/blog’/ in the URL, to avoid that you need to add a new parameter when you register the post type.

For example here in Quema Labs we have a Custom Post Type called ‘theme‘ to show our themes on the site. If we go to the code where we register this CPT and add this:


register_post_type( 'my_post_type', array(
[...]
'rewrite'  => array( 'slug' => 'theme', 'with_front' => false ),
[...]
) );

 

The important thing here is adding the option ‘with_front‘ to false. The ‘slug‘ will be different for your CPT.

With that in place we avoid the ‘/blog/‘ on our theme’s URLs.

Remember to save your permalink settings in Admin Panel after changing your rewrite rules!

 

10 comments on “How to add ‘/blog/’ in front of your URL

    1. Hey Patrick
      You can install a plugin like SEO Redirection Plugin.
      It will allow you to do 301 redirects on a per page/post basis or even using REGEX.
      I just installed it and I am going to put blog in front of my URLs. Wish me luck 🙂

  1. The step with changing category/tag base after changing the post base is not needed, categories and tags archives will be automatically prepended with the post base.

  2. Hi, when a do this process, the /blog does not appears in the breadcumbs. What can I do?

    I want my blog:

    mydomine.com/blog/category/post-1

    and the breadcumbs:

    Home > Blog > Category > Post1

    How can I add the > Blog to my breadcumbs?

    I guess it does not appear because / blog is artificially configured. Is there any way to make it hierarchical?

Leave a Reply

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

Subscribe

Subscribe to our newsletter and receive theme updates and our latest news straight into your inbox.

And you’ll receive an exclusive tutorial for your WordPress site on:

How to change your login URL