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:
So let’s add at the begining the word ‘/blog‘, it will look like this:
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:
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!