Static pages outside WP directory sending 404 http status headers (9 posts)

  1. Hi there.

    I am integrating a WP blog with a existing static website. In order not to have to maintain two different header & footer files - as well as to avoid redoing all the static pages to point to a WP header/footer, I have instead linked the WordPress blog theme files to the existing site header & footer files like this:

    include($_SERVER['DOCUMENT_ROOT'] . "/includes/header.inc.php");

    I added the WordPress hooks into the existing header as well. Here's the code for header.inc.php:


    Everything works well, but I've just discovered that all the static pages outside the WordPress /blog/ folder are sending "404 error" HTTP status headers to the browser, which is obviously not acceptable.

    I get this error when trying to validate the HTML on the static pages:

    I got the following unexpected response when trying to retrieve <http://nom.zooninidev.com/family-camp.php>:

    404 Not Found

    I am also seeing <body class="error404"> in all the static pages as well. Somehow, these pages are being interpreted by WP as nonexistent.

    If anyone knows how to correct this I would be grateful. Obviously we can't go live until this is fixed. Thanks in advance.

  2. pluc
    Posted 5 years ago #

    You're trying to re-do something that WordPress does out of the box. There is no correct way to force WordPress instanciations in places where WordPress has nothing to do. By that, I mean using stuff like wp_title() on pages that aren't store in WordPress makes little sense.

    The best (and correct) way to do what you want is to import your static pages into WordPress, and let WordPress handle your whole website - it's made specifically for people who want to have /blog/ as an independent section. I'm sure your client will be happy to be able to modify its static files through WordPress.

    You can always create a header-static.php file (and footer-static, and sidebar-static, and whatnot) and tell wordpress to get_header('static') on those specific pages.

    That's how I would do it, anyway.

  3. The best (and correct) way to do what you want is to import your static pages into WordPress, and let WordPress handle your whole website

    Thanks for your response. In this particular case I will not be able to bring the rest of the site into WordPress, although down the road that is of course an ideal solution - it's just not feasible right now for budget reasons.

    By that, I mean using stuff like wp_title() on pages that aren't store in WordPress makes little sense.

    I've actually got a condition so that the static pages do not use WP's title function:

    <title><?php if (isset($title)): /* if static title exists */
    			echo $title;
    	wp_title( '|', true, 'right' ); /* WP title function */

    Each static page has a $title variable, and where that doesn't exist (i.e. on the blog pages) I'm using the WP title function.

    I've just come across this post with the same issue:


  4. I've found the code that is causing this - it's in wp-includes/class-wp.php. Does anyone know how to override/tweak this without having to change core files?

    function handle_404() {
    		global $wp_query;
    		if ( !is_admin() && ( 0 == count( $wp_query->posts ) ) && !is_404() && !is_robots() && !is_search() && !is_home() ) {
    			// Don't 404 for these queries if they matched an object.
    			if ( ( is_tag() || is_category() || is_tax() || is_author() ) && $wp_query->get_queried_object() && !is_paged() ) {
    				if ( !is_404() )
    					status_header( 200 );
    			status_header( 404 );
    		} elseif ( !is_404() ) {
    			status_header( 200 );
  5. I also tried the methods proposed here - both in the post and comments #10 & 11 - unfortunately, neither worked.

    Fixing false 404 headers on external pages including wp-blog-header.php

  6. Chip Bennett
    Theme Review Admin
    Posted 5 years ago #

    Why not just create your own static header/footer PHP files to include in the non-WP static PHP pages?

    I would think that would entail a LOT less work than trying to hack non-WP resources to make use of WP template files.

  7. Thanks, Chip. I think I may end up having to go with two different headers/footers - was trying to avoid it (will be more cumbersome for any future updates), but unless someone has a workable solution, I think that's what I'll have to do.

  8. Jeremy Clarke
    Posted 5 years ago #

    I have to agree with Chip. You're opening a can of worms that isn't worth it. If you have time to mess with internal code stuff then you are better off spending that time doing the job properly as outlined by pluc.

    Long-term planning is always good, but in this case I think the best long term planning is to plan to fully convert the site to WordPress ASAP, rather than investing time/money in a fragile compromise that just barely works.

    FWIW here's some free advice for your client: invest the extra money to get it done right in the first place ;)

  9. Thanks a lot, Jeremy. I have gone the dual-header/-footer route. If the client eventually wants to have me convert the rest of the site into WordPress we'll do it at that point. It's a site that barely changes thoughout the year but we are creating one new page that will be updateable via WP, in addition to the new blog.

Topic Closed

This topic has been closed to new replies.

About this Topic