Tutorials, Wordpress

WordPress permalinks Blog prefix

03 August 2018

I recently found someone on the WordPress support forum who was asking how can he add /blog/ in front of his posts’, categories’ and tags’ URLs.

So I thought I’d write a post about it and share the solution with you guys. It’s quite easy actually.

1. Through Settings ( If there is no post type )
You need to:

  1. Go to Settings -> Permalinks;
  2. Under Common Settings, choose Custom Structure. The default structure there would be http://yourdomain.com/%postname%/;
  3. In front of /%postname%/, add /blog, so it will become http://yourdomain.com/blog/%postname%/;
  4. Save changes.

2. Through Custom Coding

  1. Open function.php file from the active theme folder
  2. Put the below code in it and save it
  3. Go to “Permalinks” settings and change it to other and save it, and once again save it.
  4. Now it’s all done.

add_action( 'init', 'redefine_post', 1 );
function redefine_post() {
    register_post_type( 'post', array(
        'labels' => array(
            'name_admin_bar' => _x( 'Post', 'add new on admin bar' ),
        'public'  => true,
        '_builtin' => false,
        '_edit_link' => 'post.php?post=%d',
        'capability_type' => 'post',
        'map_meta_cap' => true,
        'hierarchical' => false,
        'rewrite' => array( 'slug' => 'blog' ),
        'query_var' => false,
        'has_archive' => true,
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' )
    ) );

Leave a Comments