【问题标题】:How to create variable page title for a set of custom taxonomy pages如何为一组自定义分类页面创建可变页面标题
【发布时间】:2019-05-20 00:52:23
【问题描述】:

我正在尝试在 WordPress 中为自定义分类中的帖子设置可变页面标题

我需要标题是例如一些文字+默认帖子页面标题

所以换句话说,我只想包含原始帖子标题,但它也包含我的编辑。我有一个子主题,据我所知,这个分类没有自定义模板页面。我需要将代码添加到 archives.php 页面吗?

任何帮助将不胜感激 谢谢!

【问题讨论】:

  • 您要更改存档页面的标题还是自定义分类的单页?
  • 嗨 Sagar,非常感谢您的回复。我想更改自定义分类的单页

标签: wordpress custom-taxonomy


【解决方案1】:

您可以使用以下代码:

add_filter( 'the_title', 'modify_the_title', 10, 2 );
function modify_the_title( $title, $id ) {
    // Check for archive page.
    if ( is_archive() && is_tax( 'your-custom-taxonomy') ) {
       $title = 'some text' . $title;
        return $title;
    }
}

参考: https://developer.wordpress.org/reference/functions/is_tax/ https://developer.wordpress.org/reference/hooks/the_title/

【讨论】:

  • 我刚刚尝试过,但它不起作用 - 我尝试将它添加到我的 functions.php 和 archive.php
  • @RobertLouis 将其添加到functions.php文件中并在wp-config.php文件中启用WP_DEBUG true 并查看页面。
  • 嗨,Sagar,感谢您的帮助,但当我将它添加到 functions.php 文件时,它仍然无法正常工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-07
  • 2012-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多