0

I have a WordPress plugin that has the following code inside header.php:

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

Basically, this should happen:

  1. If subtitle is present, echo subtitle.
  2. If no subtitle is present, echo title.
  3. If 404, echo "404".

But for some reason, when I locate my 404.php page, there is nothing displayed. Why?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Muhambi
  • 3,472
  • 6
  • 31
  • 55

1 Answers1

2

If your first check is for subtitle and your 404-page has no subtitle then that part of the if-statement is triggered and all other checks are skipped. By performing the 404 check first things should work as expected.

<?php
    if (is_404()) {
        echo "404";
    } elseif (the_subtitle("","", false) == "") {
        the_title();
    } else {
        the_subtitle();
    }
?>
RST
  • 3,899
  • 2
  • 20
  • 33
  • 2
    Perhaps it might be valuable to explain as to how the statement changes answers the question. – Matt Nov 16 '14 at 23:00