最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Flushing the slug base has no effect and does not change

programmeradmin2浏览0评论

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?

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?

Share Improve this question asked Dec 13, 2020 at 14:48 DrWhoDrWho 153 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
  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' )
发布评论

评论列表(0)

  1. 暂无评论