Coder Social home page Coder Social logo

yllus / external-header-footer Goto Github PK

View Code? Open in Web Editor NEW
3.0 5.0 6.0 170 KB

A simple WordPress plug-in that exposes that site's header and footer over HTTP as external files that can be consumed, or consumes another website's header and footer. Useful on external websites that want to have consistent styling with the WordPress site.

Home Page: https://wordpress.org/plugins/external-header-footer/

PHP 100.00%

external-header-footer's Introduction

=== External Header Footer ===
Contributors: yllus
Donate link: https://github.com/yllus/external-header-footer
Tags: 
Requires at least: 3.5.2
Tested up to: 5.0.0
Stable tag: trunk
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

External Header Footer lets you expose your site's header and footer as URLs whose content can then be displayed on other websites. 

== Description ==

**External Header Footer** is a simple WordPress plug-in that exposes that site's header and footer over HTTP as URLs whose content can then be consumed. 

How is this useful? Let's say you've got a WordPress website at your **www** subdomain, and a forum for your community of users at a **forums** subdomain. In many cases, you'll want to keep the header, footer and basic styling (link, text, background colours) of both sites identical. 

That's the cue to use **External Header Footer**: Once this plug-in is enabled on **www**, run a scheduled task on your **forums** subdomain to retrieve and locally store (write to a file, or to memory) the header and footer to be displayed on that site every day/hour/week. Now with minimal effort you can be assured that both sites will maintain a consistent look and feel.

== Installation ==

1. Enable **External Header Footer** within the **Plugins** > **Installed Plugins** interface.

2. Head over next to the settings page for the plug-in at **Settings** > **External Header Footer**.

3. Check the **Expose Header and Footer** checkbox and click the **Save Changes** button.

4. The settings page should return with a message indicating your changes have been saved. The page will also list three URLs that are now ready for viewing and use. The **Demo Page URL** provides a demonstration of what some sample content will look like when the header and footer are read in and then displayed at the top and bottom of that page - check out the (very straightforward) source code of test-page.php to understand how to use this plug-in on your external website(s).

5. On the WordPress side of things, your work is done. To finish up, set up your external website(s) to retrieve from **Header URL** and **Footer URL**, sandwiching the actual content of the site in between them. 

== Frequently Asked Questions ==

= Consuming an External Header and Footer to display on your WordPress Site =

1. If not already done, enable **External Header Footer** within the **Plugins** > **Installed Plugins** interface.

2. Head over next to the settings page for the plug-in at **Settings** > **External Header Footer**.

3. 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).

4. Verify that the **Cache Header/Footer For** setting contains an appopriate value that is denominated in minutes.

5. Click the **Save Changes** button.

6. 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.

7. 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 http://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.

== Screenshots ==

1. The settings page for External Header Footer allows you to enable/disable whether or not your WordPress website's header and footer will be available for external consumption (**Expose Header and Footer**). If that option is checked, the **Header URL** and **Footer URL** fields display the URLs that should be retrieved by external websites when using your site's header and footer.

   Within the **Consume Header / Footer from External Website** section, you can optionally consume another site's header and footer, and then use the provided PHP functions to output them to your WordPress site's pages.

2. This displays what's found at the **Demo Page URL**; namely, some placeholder text wrapped by your site's header and footer.

== 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.

== Upgrade Notice ==

= 1.0.2 =
* Bump plug-in compatibility to WordPress v5.0.0.

= 1.0.1 =
* Adds the "Force Use Of HTTPS" and "Force Use Of Absolute URLs" features, bumps compatibility to v4.2.4.

= 1.0 =
* Initial release.

external-header-footer's People

Contributors

yllus avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

external-header-footer's Issues

More than just the header

Hello,

I want to retrieve more than just the header, to be more accurate I want to retrieve the header and some HTML markup. Is there any way to do that ?

Regards

Nikos

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.