【发布时间】:2015-07-16 20:06:37
【问题描述】:
我在修改存档页面的页面标题时遇到了一点问题。我有一个电影的自定义帖子类型,我似乎无法更改它。现在它显示“电影档案”。我想把它完全改成“程序”之类的东西。
有什么想法吗?
谢谢!
【问题讨论】:
标签: wordpress post types title archive
我在修改存档页面的页面标题时遇到了一点问题。我有一个电影的自定义帖子类型,我似乎无法更改它。现在它显示“电影档案”。我想把它完全改成“程序”之类的东西。
有什么想法吗?
谢谢!
【问题讨论】:
标签: wordpress post types title archive
这取决于您的模板用于输出自定义帖子类型存档标题的功能。
我猜它正在使用wp_title 或get_the_archive_title,因此您可以尝试添加过滤器(在您的主题的functions.php 内):
function movies_archive_title( $title ) {
if(is_post_type_archive('movie'))
return 'Programme';
return $title;
}
add_filter( 'wp_title', 'movies_archive_title' );
add_filter( 'get_the_archive_title', 'movies_archive_title' );
如果查看的页面是电影档案(确保将 'movie' 替换为您的自定义帖子类型名称的确切名称),那么它将标题替换为 Programme。
【讨论】:
get_the_archive_title()。检查帖子类型名称:找到带有register_post_type( 'post_type_name', ...的行
您可以像这样在functions.php 中添加过滤器来覆盖标题,但保留站点名称和标题分隔符:
function movies_archive_title( $title ) {
$site_name = get_bloginfo();
$sep = apply_filters( 'document_title_separator', '|' );
$sep = str_pad( $sep, 30, " ", STR_PAD_BOTH );
if(is_post_type_archive('movie'))
return 'Programme'.$sep.$site_name;
return $title;
}
// Raise priority above other plugins/themes that
// have effect on the title with 900 (the default is 10).
add_filter( 'wp_title', 'movies_archive_title', 900 );
add_filter( 'get_the_archive_title', 'movies_archive_title', 900 );
将movie 替换为您的自定义帖子类型名称,将Programme 替换为上例中所需的标题。
对于某些插件和主题,您需要使用add_filter 方法的priority 参数提高优先级,否则您将看不到任何更改。
【讨论】: