首页 文章

Wordpress如果404 Headers

提问于
浏览
0

我有一个wordpress插件,在header.php中有以下代码:

<?php
    if (the_subtitle("","", false) == "") {
        the_title();
    } elseif(is_404()) {
        echo "404";
    } else {
        the_subtitle();
    }
?>

基本上应该发生的是:

  • 如果字幕存在,则回显副 Headers .

  • 如果没有字幕,则回显 Headers .

  • 如果404,则回显"404" .

但出于某种原因,当我找到我的404.php页面时,它们没有显示出来?

1 回答

  • 2

    如果您的第一次检查是针对 subtitle 而您的 404 页面没有 subtitle 则会触发 if-statement 的那部分并跳过所有其他检查 . 通过执行 404 检查,首先应该按预期工作 .

    <?php
        if (is_404()) {
            echo "404";
        } elseif (the_subtitle("","", false) == "") {
            the_title();
        } else {
            the_subtitle();
        }
    ?>
    

相关问题