5
votes

As default wordpress came with a default post type with the slug of "post"!

I wanna change this slug to another one without any headache!

I mean, for example, change the slug post to article.

How can i achieve that ?

Update

This is what i want :

function _slug(){
 $args = array(
    'rewrite' => array(
        'slug' => 'article',
    ),
  ); 
  register_post_type('post',$args);
}
add_action('init', '_slug');

But, well that doesn't work!

1
Check under Settings > Permalinks - Jrod
@Jrod that's not correct! i meant change it from base - revo
The base structure for post permalinks is usually set in the permalinks settings panel. If this is not the case for your installation do you know whether or not wordpress has been installed inside a folder called post? Can you provide a link to your project? - Jrod
@Jrod actually that's not my case otherwise that's obvious! - revo
@Jrod i want to rename post type slug - revo

1 Answers

0
votes

One of the ways is to use a post type args filter on functions.php file (make sure it run after post type registered):

$post_type = <POST TYPE NAME> # Define your own as a string
$new_slug = <WANTED SLUG> # Define your own as a string

add_filter( 'register_post_type_args', function($args, $post_type){
  if ( 'post_type' == $post_type )
     $args['rewrite'] = array( 'slug' => $new_slug );

  return $args;

}, 10, 2 );