3

I'm trying to change the default slug for default wordpress post.

With register_post_type works fine with this code:

add_action( 'init', 'my_new_default_post_type', 1 );
function my_new_default_post_type() {

    register_post_type( 'post', array(          
        'rewrite' => array( 'slug' => 'blog' ),         
    ) );
}

But with recent register_post_type_args is not possible. This is my code:

add_filter( 'register_post_type_args', 'new_register_post_type_args', 10, 2 );
function new_register_post_type_args( $args, $post_type ) {

    if ( 'post' === $post_type ) {      

        $args['rewrite']['slug'] = 'blog';

    }

    return $args;
}

Any ideas?

3
  • Singe 'rewrite' takes an array, you could try changing the args line to $args['rewrite'] = array('slug' => 'blog');
    – WebElaine
    Commented Apr 18, 2017 at 15:48
  • Related - you can just change permalinks rather than use the filter - wordpress.stackexchange.com/questions/131666/…
    – WebElaine
    Commented Apr 18, 2017 at 15:51
  • 1
    @WebElaine that does not work. I think your code is the same that $args['rewrite']['slug'] = 'blog'
    – kurtko
    Commented Apr 18, 2017 at 16:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.