Rewrite default post type

I would like to rewrite the default post type URL to /blog/2016/11/my-post-name/ without affect the other post type url. I tried:

add_action('admin_menu','remove_default_post_type');
function remove_default_post_type() {
    remove_menu_page('edit.php');
}

add_action( 'init', 'set_default_post_type', 1 );

function set_default_post_type() {
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/%year%/%monthnum%/%postname%/',
            'with_front'=> false,
        ),
        'query_var' => false,
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
    ) 
 );
}

But with no success. The url stay as /blog/my-post. Is there one way to have permalinks of default post type like /blog/2016/11/my-post-name/ (where 2016 is the year of post and 11 is the month of post) Without affect others post types urls?

2 s
2

Use the field in the admin Settings > Permalinks page to set your permalink structure to /blog/%year%/%monthnum%/%postname%/.

To prevent custom post types from inheriting the post permalink structure, set with_front to false in your register_post_type arguments for all custom post types.

Version 4.4 also added the register_post_type_args filter to allow modification of post type arguments for types registered by code you don’t have access to change.

Leave a Comment