How to add /blog/ permalink only for post types?

  • Moises
    Moises
    Newbie 25 points
    June 28, 2016 at 5:52 pm

    I would like to add /blog/ to my posts to make it easier to monitor posts from my blog with Google Analytics. The current structure is:

    post listing page: example.com/blog
    individual post: example.com/post-name

    I’d like it to become example.com/blog/post-name.

    My current permalink structure is set up to be /%postname%/ and if I change to /blog/%postname%/ it affects the other post types

  • Aaron
    Aaron
    Super Guru 920 points
    June 28, 2016 at 10:54 pm

    Something like this should work:

    function default_post_slug() {
    register_post_type( 'post', array(
    'rewrite' => array( 'slug' => 'blog' ),
    ) );
    }
    
    add_action( 'init', 'default_post_slug', 5 );

    Just add it to your childthemes functions.php file.

    This reply was awarded the best answer by the topic poster.
  • Moises
    Moises
    Newbie 25 points
    July 1, 2016 at 2:32 am

    Thank’s Aaron!


  • Josh
    Super Guru 13,875 points
    July 1, 2016 at 1:33 pm

    Thanks for sharing Aaron 🙂

Viewing 4 posts - 1 through 4 (of 4 total)

New Business Themes for WordPress 2020

Start your new website today!

View Business Themes