WordPress:自定义< title>用于存档页面 [英] Wordpress: Custom <title> for archive pages

查看:102
本文介绍了WordPress:自定义< title>用于存档页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在修改存档页面的页面标题时遇到了一些麻烦.我有电影的自定义帖子类型,但似乎无法更改它.现在,它显示为电影档案".我想将其全部更改为"Programme".

I'm having a little trouble modifying the page title for my archive pages. I have a custom post type for movies, and I can't seem to alter it. Right now it reads "Movies archive". I'd like to change it altogether to something like "Programme".

有什么想法吗?

谢谢!

推荐答案

这取决于模板用于输出自定义帖子类型档案的标题的功能.

It depends on the function your template is using to output the title of your custom post type archive.

我猜它正在使用 wp_title get_the_archive_title ,因此您可以尝试添加过滤器(在内部您的主题的functions.php ):

I guess it's using either wp_title or get_the_archive_title so you can try adding a filter (inside functions.php of your theme):

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 .

If the page viewed is the movies archive (be sure to replace 'movie' with the exact name of your custom post type name) then it replace the title with Programme.

这篇关于WordPress:自定义< title>用于存档页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆