Reputation: 31
I'm having trouble with adding a custom php page to have wp style (header and footer), and i succeeded but the issue is that it appears as a 404 error not a 200 success.
the header is like this:
<?php
include $_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php";
include $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/theme_name/header.php";
?>
and i NEED to have this page like an is_single
or is_page
or something to not be 404 page with that error.
i tried:
global $wp_query;
$wp_query->is_404 = false;
and:
global $wp_query;
$wp_query->is_page = true;
but both didn't work, please help!
Upvotes: 3
Views: 2376
Reputation: 1690
I had this problem as well but the following worked well for me in Wordpress 4.7
<?php
define('WP_USE_THEMES', false);
if ( !isset($wp_did_header) ) {
$wp_did_header = true;
require( $_SERVER['DOCUMENT_ROOT'].'/wp-load.php' );
wp();
//$wp_query->is_page = true;
global $wp_query;
$wp_query->is_404 = false;
//require_once( ABSPATH . WPINC . '/template-loader.php' );
}
get_header();
?>
<?php get_footer();?>
Upvotes: 0
Reputation: 2162
You should use wp-load.php
, not wp-blog-header.php
. because the usage of wp-blog-header.php si only for wordpress files not out side files.
Upvotes: 7
Reputation: 6039
Take a look at this link:
https://gist.github.com/gyrus/3332597.
I think the key is that you have to call status_header( '200' );
in order to get it to work.
Here's another relevant link: http://sltaylor.co.uk/blog/intercept-wordpress-404s/
Upvotes: 0