Many people embed my website's pages in their websites as iframes. I want them to not take my footer, header and a specific division in those iframes. Since, footer, header and mentioned specific division is present in all of my pages.

What should I do? Should I add some code in my header or in my functions.php file?

  • 1
    There is no simple way to detect if request is coming from an iframe. You would have to devise a complex system of detection that persists across all subsequent session requests, not just the first and initial request. – Scriptonomy Nov 10 '15 at 4:38

You could detect the $_SERVER['HTTP_REFERER'] variable to detect whether the page is requested from an external server. If so, then you should load an alternative header and footer using get_header() and get_footer(). You'll need those calls to make sure all scripts and stylesheets are loaded, but you can remove the other content that make up the actual header and footer elements.

For example you could duplicate your current header.php to header-iframe.php and call the header with:


The same thing goes for the footer. Create a file called footer-iframe.php and call it using:


Just make sure your header-iframe.php contains everything up to the opening tag, like this:

<html <?php language_attributes(); ?>>

    <meta charset="<?php bloginfo( 'charset' ); ?>" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />

    <title><?php wp_title( '|', true, 'right' ); ?></title>
    <?php wp_head(); ?>


<body <?php body_class('iframe'); ?>>

Your footer-iframe.php should be stripped of all excess content, like this:

<?php wp_footer(); ?>


The above snippets are just an example, but you get the idea. Calling the get_header('iframe'); and get_footer('iframe); functions should be conditional based on the $_SERVER['HTTP_REFERER'] variable. This could be done using preg_match or any other native PHP comparison function.


Why don't you create a specific template just for embedding? In your custom template, you could just remove the get_header(), get_footer() and get_sidebar() calls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.