Stop WordPress Entirely and Run My Own Code

I have a site that must be deployed in a WP Multisite environment but none of the code in the site uses WordPress at all. How can I intercept WordPress, perhaps at ‘init’, and tell it to stop doing anything and let me take over?

I tried just putting everything in my index.php file and include everything manually from there. However, this results in the <head> of my page being loaded within the body. So it’s obvious that I need to interrupt WordPress before it can run wp_head(), but don’t know how this might be done.

Related posts

Leave a Reply

1 comment

  1. You could hook init and check the current blog ID

    function wpa85780_my_app_init(){
        $my_blog_id = 99;
        if( $my_blog_id == get_current_blog_id() ):
            include 'somefile';
            exit;
        endif;
    }
    add_action( 'init', 'wpa85780_my_app_init' );
    

    This will exit before WordPress does the main query and loads the template.

    EDIT

    a slightly earlier action you could hook is after_setup_theme, that seems to be the earliest that get_current_blog_id will work. See the action reference page for the order of actions.