External Header Footer lets you expose your site's header and footer as URLs whose content can then be displayed on other websites.
FAQ
Consuming an External Header and Footer to display on your WordPress Site
-
If not already done, enable External Header Footer within the Plugins > Installed Plugins interface.
-
Head over next to the settings page for the plug-in at Settings > External Header Footer.
-
Enter a valid URL into the External Header URL and External Footer URL fields (or leave one or the other blank if you only need one of the two).
-
Verify that the Cache Header/Footer For setting contains an appopriate value that is denominated in minutes.
-
Click the Save Changes button.
-
The settings page should return with a message indicating your changes have been saved. Next, click on the URL for the External Demo Page URL to see a demonstration of what a page wrapped with the specified external header and footer would appear like.
-
To display the external header on a page, simply call the following function:
ehf_output_external_header();
Similarly, call the following function to output the external footer to a page:
ehf_output_external_footer();
Note: Through use of the best caching system available on your WordPress site, the HTML markup for the header and footer will be saved to your local WordPress website, and only re-retreived when the cache expiry value is reached. Of course, any CSS, JavaScript or image assets on the external site will be retrieved from that site by your site visitors.
Advanced Usage
Sometimes the contents of your header or footer will cause conflicts or problems if displayed on an external website: Let’s say you’re using the popular Google Analytics for WordPress plug-in on your WordPress site, but your external website has its own Google Analytics code, and you don’t want to get the two mixed together. No problem – but it will take a little bit of code.
Two new WordPress Actions are included as part of this plug-in; both allow you to run your own code immediately before the external header and footer are displayed at their new individual URLs:
external_header_footer_pre_header
external_header_footer_pre_footer
Let’s say you need to stop Google Analytics for WordPress from In your theme’s functions.php file, write a function that removes the addition of JavaScript code for Google Analytics by removing the action that adds to your site’s header. Then simply call hook your function to the external_header_footer_pre_header action. Here’s an example of that code:
function remove_ga_from_external_header() {
// Remove the addition of AdSense JavaScript code from the header.
remove_action( 'wp_head', array( 'GA_Filter', 'spool_adsense' ), 1 );
// Remove the addition of Google Analytics JavaScript code from the header.
remove_action( 'wp_head', array( 'GA_Filter', 'spool_analytics' ), 2 );
}
// Call the function remove_ga_from_external_header() immediately before the external header is displayed (at its individual URL).
add_action('external_header_footer_pre_header', 'remove_ga_from_external_header');
Use the external_header_footer_pre_footer and the same technique – use of remove_action or remove_filter – to ensure only the code you want to go out as part of the footer is output.
Tips & Tricks
-
Avoid having the header and footer retrieved every time your external website displays a page. Instead, see if you can schedule a task to retrieve the header and footer occasionally (say, once an hour) and save it to the external website’s diskspace. Then output the contents of those files when pages are requested on the external website.
-
Ensure that the URLs in your header and footer are absolute to ensure that they point to pages that exist when they’re being displayed on an external website. For example, if you’ve got the following URL coded into your header to point to your “About Us” page:
<a href="/about-us/">About Us</a>
You can use the standard WordPress function home_url() to ensure that the URL is output in absolute form:
<a href="<?php home_url('/about-us/'); ?>">About Us</a>
For more information, check out the WordPress Codex entry for home_url at https://codex.wordpress.org/Function_Reference/home_url .
-
Need to clear the cache of an external header/footer immediately? No problem – clicking the Save Changes button on the settings page for this plug-in do exactly that.
ChangeLog
1.0.2
- Verified compatibility with WordPress v5.0.0. Cleaned up readme.txt line breaks.
1.0.1
- Adds a “Force Use Of Absolute URLs” option that automatically rewrites URLs that are relative to the site’s root to be absolute URLs instead.
- Adds a “Force Use Of HTTPS” option that automatically rewrites all URLs pointing to your WordPress site’s domain in your header and footer to a HTTPS version of those links instead.
1.0
- Initial release; tested compatibility with WordPress v3.9.2.