Flushing the slug base has no effect and does not change

I’m trying to change the actor slug base, but when refreshing the permalinks everything remains the same. I am using the following code that I found to achieve it:

function space_change_custom_taxonomy_slug_args( $taxonomy, $object_type, $args ){
    if( 'actor' == $taxonomy ){ // Instead of the "old-slug", add current slug, which you want to change.
        remove_action( current_action(), __FUNCTION__ );
        $args['rewrite'] = array( 'slug' => 'star' ); // Instead of the "new-slug", add a new slug name.
        register_taxonomy( $taxonomy, $object_type, $args );
    }
}
add_action( 'registered_taxonomy', 'space_change_custom_taxonomy_slug_args', 10, 3 );

The theme has the following register taxonomy:

// Now register the non-hierarchical taxonomy like tag
    register_taxonomy('actors','post', array(
        'hierarchical' => false,
        'labels' => $labels,
        'show_ui' => true,
        'show_admin_column' => true,
        'update_count_callback' => '_update_post_term_count',
        'query_var' => true,
        'show_in_rest' => true,
        'rewrite' => array( 'slug' => 'actor' )
    ));

I do not know what I’m doing wrong. And a doubt that I have. It is better to use this code in functions or use a url rewrite rule from .htaccess?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

  1. In your first function, the taxonomy doesn’t match what’s registered in the second (‘actor’ instead of ‘actors’)
  2. Alternatively, just edit it in the ‘rewrite’ argument of the second function, i.e: 'rewrite' => array( 'slug' => 'star' )


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x