Load only page content if url contains php parameter

I’m trying to load load only the page content (prevent loading header menu or footer) if the url contains ?mode=quick

I’ve tried adding the following to the top of my header.php to try only loading the content of the page but it didn’t work.

Read More
<?php
    if ($_GET['mode'] == 'quick'){
        the_content();
        exit();
    }
?>

I was able to prevent the footer from loading by adding the following code to page.php before the last line.

<?php
    if ($_GET['mode'] == 'quick'){
        exit();
    }
?>

<?php get_footer(); ?> // Last line

Is there a way to do a similar thing but prevent the header from loading as well?

Related posts

4 comments

  1. index page

    require "pages/".$page.".php";
    
    require_once("layouts/footer.php");
    ?>
    

    header.php

              $page = "home";
                if(isset($_GET['page'])){
                    if($_GET['page']=='quick'){          
                      $page = $_GET['page'];
                    }
                }
    

    I hope it will be helpful for you

  2. You simply need to invert where you put your logic:

    <?php
        // Only show the header if 'mode' is NOT set or set to something not equal to 'quick'
        if (!isset($_GET['mode'] || $_GET['mode'] != 'quick'){
            get_header();
        }
        the_content();  //This is the one part that is ALWAYS shown
        if (!isset($_GET['mode'] || $_GET['mode'] != 'quick'){
            get_footer();
        }
    ?>
    
  3. The solution I found was to create a duplicate of header.php and rename it to header-empty.php

    I modified the code in the new header file to strip it down. Then I had it conditionally load that header if the url parameter was correct.

    WordPress requires the get_header() function so I couldn’t avoid calling it.


    Beginning of page.php

    <?php 
        if (isset($_GET['mode']) && $_GET['mode'] == 'quick'){
            get_header('empty');
        } else {
            get_header();
        }
    ?>
    

    End

    <?php
        if (isset($_GET['mode']) && $_GET['mode'] == 'quick'){
            exit();
        }
    ?>
    <?php get_footer(); ?> // Last line
    

Comments are closed.