我有一个自定义帖子类型,名称为“ Portfolio”。当我发表任何文章时,它会以/ portfolio / xxx的形式生成网址。我想将其更改为“产品”。更改自定义帖子类型重写我已经尝试过了,但是它不能正常工作。
我假设您自己添加了自定义帖子类型,在这种情况下很容易。
注册新的帖子类型时,可以设置该帖子类型的所有重写规则,以作为该函数中使用的参数的一部分register_post_type( 'name', $args )
。
如果您的帖子类型在前端可用并且是公开的,则默认情况下WordPress将使用自定义帖子名称作为首词。您可以按如下方式覆盖它:
$args = array(
// your other arguments
'rewrite' => array(
'slug' => 'products', // use this slug instead of post type name
'with_front' => FALSE // if you have a permalink base such as /blog/ then setting this to false ensures your custom post type permalink structure will be /products/ instead of /blog/products/
),
);
register_post_type( 'portfolio', $args );
您可以使用的其他参数记录在http://codex.wordpress.org/Function_Reference/register_post_type中
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句