更改“POST"在 wordpress 中输入 slug [英] Change "POST" type slug in wordpress
本文介绍了更改“POST"在 wordpress 中输入 slug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
作为默认的 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!
我的意思是,例如,将 slug post
更改为 article
.
I mean, for example, change the slug post
to article
.
我怎样才能做到这一点?
How can i achieve that ?
更新
这就是我想要的:
function _slug(){
$args = array(
'rewrite' => array(
'slug' => 'article',
),
);
register_post_type('post',$args);
}
add_action('init', '_slug');
但是,这行不通!
推荐答案
其中一种方法是使用 post type args filter onfunctions.php 文件(确保它在帖子类型注册后运行):
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 );
这篇关于更改“POST"在 wordpress 中输入 slug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文