Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change "POST" type slug in wordpress

Tags:

wordpress

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!

like image 817
revo Avatar asked Nov 24 '22 04:11

revo


1 Answers

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 );

like image 149
Amit Rahav Avatar answered Feb 08 '23 02:02

Amit Rahav