0
function debug($message){

   error_log($message, 3, get_template_directory() . '/debug.log');

}

I added the above function to each of the templates.

For example, front-page.php includes a line that goes like this: debug("front-page.php \n");

I use tail -f debug.log in the terminal to determine which templates are being used by a particular page. Here is the result.

enter image description here

5
  • 1
    how are you testing that these log lines are coming from the same page request? This could be as trivial as an image tag with a broken src="/" in your 404 template
    – Tom J Nowell
    Feb 6 at 15:12
  • I just added the debug function to each template with the corresponding name. When I refresh the page (for example, front page), the log in the terminal shows both front-page and 404, indicating that the page is using both the templates.
    – SuPalle
    Feb 6 at 15:17
  • I don't think that's enough, at a minimum you should include the current URL in the message, what you're describing is not how WordPress templating works and you should be seeing 2 pages one above the other, or, one inside the other, but that's not what you described. Instead it's more likely that one page triggers a second request which is why you're seeing 2 templates loaded, and the URL will help inform what's doing that
    – Tom J Nowell
    Feb 6 at 15:20
  • 1
    It could be as simple as a broken asset URL for a CSS file etc
    – Tom J Nowell
    Feb 6 at 15:22
  • You were right. Thank you for helping me find the bug. It was indeed a broken link to a CSS file.
    – SuPalle
    Feb 7 at 15:19

1 Answer 1

1

I used the following function to retrieve the URLs of each page.

  function template_debug($filename = null) {
        $url = home_url($_SERVER['REQUEST_URI']);
        debug("Called from: $filename using URL $url \n");
    }

Then I inspected the front page which triggered the 404 template along with the front-page template. The Network Monitor tab showed the error, which was an incorrect folder name included in the CSS file.

After making the necessary changes, the 404 template isn't being triggered anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.