如何在wordpress中更改特定类别的slug?

rnmwe5a2  于 2023-01-01  发布在  WordPress
关注(0)|答案(1)|浏览(182)

对于特定类别的帖子插件添加自定义文本,如'博客'之前的类别名称。
之前:https://shiphero.com/article/how-to-stay-on-top-of-warehouse-storage-and-organization/之后:https://shiphero.com/blog/article/how-to-stay-on-top-of-warehouse-storage-and-organization/

shyt4zoc

shyt4zoc1#

add_filter( 'post_link', 'custom_permalink', 'author_link', 10, 3 ); 

function custom_permalink( $permalink, $post, $leavename ) { 
    $category = get_the_category($post->ID); 
    if ( !empty($category) && $category[0]->cat_name == "Exclude from list" ) { 
        $cat_name = strtolower($category[0]->cat_name); 
        $authordata = get_userdata( $post->post_author ); 
        $author = $authordata->user_nicename; 
        $permalink = trailingslashit( home_url('/blog/article/' . $post->post_name . '/' ) ); 
    } 
    return $permalink; 
}

相关问题