【问题标题】:Displaying page title issue显示页面标题问题
【发布时间】:2014-11-20 02:54:34
【问题描述】:

我有一个 Wordpress 应用程序,它根据页面显示标题:

<?php
    if (is_404()) {
      echo "404. Page not found.";
    } elseif (is_page('46')) {
      echo "NOT WORKING";
    } elseif (the_subtitle("","", false) == "") {
        the_title();
    } else {
        the_subtitle();
    }
?>

基本上,在特定页面(第 46 页,我已通过打印页面 id 确认)上,我想显示特定标题。但是由于某种原因,当我访问第 46 页时,我得到的是页面的标题,而不是“不工作”?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    如果此代码在您的 functions.php 文件中,您将需要一个操作或过滤器以使其在适当的时间运行。下面是一个示例,说明您可以添加到 functions.php 文件中以实现您正在寻找的结果:

    function to_update_title( $title, $id = null ) {
    
        if (is_404()) {
            return "404. Page not found.";
        } elseif (is_page('46')) {
            return "NOT WORKING";
        } elseif (the_subtitle("","", false) == "") {
            return get_the_title();
        } else {
            return get_the_subtitle();
        }
    
        return $title;
    }
    add_filter( 'the_title', 'to_update_title', 10, 2 );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      • 2014-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-06
      相关资源
      最近更新 更多