【问题标题】:Change "POST" type slug in wordpress在 wordpress 中更改“POST”类型的 slug
【发布时间】:2013-02-16 12:33:30
【问题描述】:

由于默认的 wordpress 带有一个带有“post”的默认帖子类型!

我想把这个蛞蝓换成另一个没有任何头疼的东西!

我的意思是,例如,将 slug post 更改为 article

我怎样才能做到这一点?

更新

这就是我想要的:

function _slug(){
 $args = array(
    'rewrite' => array(
        'slug' => 'article',
    ),
  ); 
  register_post_type('post',$args);
}
add_action('init', '_slug');

但是,那行不通!

【问题讨论】:

  • 在“设置”>“永久链接”下检查
  • @Jrod 这不正确!我的意思是从基础更改它
  • 帖子永久链接的基本结构通常在永久链接设置面板中设置。如果您的安装不是这种情况,您是否知道 wordpress 是否已安装在名为 post 的文件夹中?你能提供一个你的项目的链接吗?
  • @Jrod 实际上这不是我的情况,否则这很明显!
  • @Jrod 我想重命名帖子类型 slug

标签: wordpress


【解决方案1】:

其中一种方法是在functions.php文件上使用帖子类型args filter(确保它在帖子类型注册后运行):

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

【讨论】:

    猜你喜欢
    • 2020-02-15
    • 2017-03-30
    • 2018-11-15
    • 2019-02-16
    • 2022-12-30
    • 1970-01-01
    • 2017-01-31
    • 1970-01-01
    • 2014-02-17
    相关资源
    最近更新 更多