Support » Fixing WordPress » Theme’s 404.php is being loaded “behind the scenes”

  • So after a lot of debugging I’ve found this to be the situation.

    My theme’s 404.php has an error_log print on it. I see it keeps being called every page load, sometimes numerous times. Even though the pages are loading fine.

    I eventually found it to be because, in the HTML, there are broken images. (Test encironment, the images don’t exist on the server.)

    For some reason, each time the page “encounters” one of these, the entire 404.php template – which means the theme’s header, sidebars, widgets, etc – are all processed and “rendered” – just not visually.

    This has to do with .htaccess.
    If I delete the standard .htaccess file, this does not occur. If I re-save permalinks to post-name, my pages work again but this 404 issue keeps happening.

    How to resolve this?

    • This topic was modified 6 months, 1 week ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 3 replies - 16 through 18 (of 18 total)
  • @ftlralph

    Maybe what you need is

    $uri = $_SERVER['REQUEST_URI'];
    error_log($uri); // This will output current URI in the error log.

    in your 404.php template.


    Since you have access to the server, maybe better solution for analyzing 404 pages, would be to get the access logs, and parse it through some utility like AWStat or GoAccess, which will allow you to figure out whats actually happening, and which URLs are giving 404.

    The standard behavior in WordPress is that all calls don’t match an existing directory or file will be handled by WordPress.
    If WordPress after analyzing the request comes to the conclusion that this should be a 404, then the theme’s 404-php will be called.

    Have you tried something like (I haven’t tried it myself, just found it by serching for “404 log” in the plugin directory.)

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Theme’s 404.php is being loaded “behind the scenes”’ is closed to new replies.