Including custom php page to wordpress without being 404 error

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:

Read More
<?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!

Related posts

Leave a Reply

3 comments

  1. 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();?>