0

I have a bit of content in a PHP file that is designed to live inside an iframe on another page. The PHP file is very simple-- here it is in its entirety right now:

<div class="content-tos">
    <?php
        // get the terms of service from other page
        $getpage = get_page_by_path('/terms-of-service');
        echo apply_filters('the_content', $getpage->post_content);
    ?>
</div>

Obviously I need to include something above these lines of code so the PHP has access to the Wordpress core functions (like get_page_by_path())... but if I use get_header() I get my entire header, nav bar, Google Analytics tracking code etc, which then appear inside the iframe, which I definitely don't want.

Is there a way in Wordpress to do some kind of include that will give me the basic Wordpress API but won't draw a full HTML header, etc, etc, etc from the header.php file?

1
  • so the PHP has access to the Wordpress core functions. I don't understand, what do you need to get from the header Commented Aug 31, 2015 at 18:30

2 Answers 2

2

If you don't want get_header, then don't call get_header(). It's a simple as that, the get_header function is not where all of the WP core is initialized. The simplest way to do this is using the template hierarchy to create a template for a specific page slug or id.

From the WP Admin, create a page at the URL you want to use.

http://example.com/tos

Then create a template file that follows the rules for overriding the template for that specific page.

wp-content/themes/<your-theme>/page-tos.php

From there you can put whatever you want in page-tos.php and have full access to WP functions and API. And you can disable it by simply unpublishing the page from the WP Admin as well.

0
0

Think perhaps you're confusing get_header() with the file wp-blog-header.php. The first is a theming function generally used to pull stuff into the <head> section of your HTML. The file wp-blog-header.php essentially bootstraps WordPress.

Try this:

<div class="content-tos">
    <?php
        require('/path/wordpress/wp-blog-header.php');
        // get the terms of service from other page
        $getpage = get_page_by_path('/terms-of-service');
        echo apply_filters('the_content', $getpage->post_content);
    ?>
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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