Using WordPress header and footers externally
I needed to integrate a WordPress header (header.php) and footer (footer.php) into an external application.
There are quite a few ways round this, but none are really ideal. For example, if you want to include an external page in WordPress for whatever reason, you could use the Exec-PHP plugin. Simple, hey? No.
What if that page does something a little bit tricky that can't be run through PHP's eval();?
I ran into these problems whilst integrating a 3rd party web application with a new WordPress.
We needed both sites to look exactly the same, ideally, using the WordPress theme as it creates all the page links etc for us.
How do we do it? Simple. I wrote a wrapper to download and save these two files so the 3rd party app can access them.
Here's my shell script, called update_headers.sh
- #!/bin/bash
- rm -rf header-wrapper.html && wget http://YOUR_URL/header-wrapper.php -O header-wrapper.html -q
- rm -rf footer-wrapper.html && wget http://YOUR_URL/footer-wrapper.php -O footer-wrapper.html -q
It calls wget to download two simple files from the WordPress directory.
header-wrapper.php looks like this
- <?php
- require('./wp-blog-header.php');
-
- include $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/new_theme/header.php";
- ?>
and footer-wrapper.php looks like this
- <?php
- require('./wp-blog-header.php');
-
- include $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/new_theme/footer.php";
- ?>
So, the script calls the header and footer wrapper, saves the file to the web root (or where ever you ran the script from, ready to be included by your 3rd party app.
This particular application uses the Smarty template engine, so all I needed to do was replace the appliaction's header code with the following line
and of course, your footer will look similar.
Whenever the client updates the WordPress pages, for example adds a new page etc, we just call the shell script. Or, if you're lazy, set it to run every hour from cron.
"A bit clunky", you say? Well you find a better way!
Related posts
- PHP Header Redirects
There's a few ways to redirect a page in PHP. Well, two. A right and... - Cleaning up WordPress Header
WordPress implements some HTML standards compliant code in the top of every page. Sometimes you... - Really Simple WordPress Post Filtering
Sometimes you don't want to show every post category on your WordPress site home page,... - Debugging WordPress
Debugging WordPress is actually quite simple. Stop yourself going grey and or bald. In your... - WordPress function remove_menu_page
WordPress is now being used more and more for a full site CMS and the...




September 26th, 2008 - 15:43
If only you were in the same place as I am, I’d really buy you a beer and I’d be glad to shake my hands with you on this. Thank you for sharing.
January 20th, 2009 - 16:50
Hi, i have a similar, but yet quite different issue i’ve been trying to figure out for few days now.
i have installed wordpress on my domain psykoid.com. i need to add a *.php file in my root directory, so that it is accessed via psykoid.com/*.php.
i want to use my blog’s header and footer html so that *.php looks the same, but i can’t get the static html. is there such a way?
February 23rd, 2009 - 04:31
hello there, I think this is what I am needing to use for my 3rd party support script (whmcs) (also uses smarty) but I am not clear on where the files should go after they have been created.
I’ve never dealt with a shell script, so exactly how do I make it work? Also, where do the .html files listed in the shell script come into play?
Thanks for any clarification you can give to this non-programmer!
August 16th, 2009 - 13:46
Excellent! However, I did it slightly differently.
Created a new index.php file in a seperate folder did include the ../wp-blog-header.php then copied the content of wp-content/themes/MyTheme/page.php over into the index.php file
Modified a little to suit my need and make this index.php file read content of other files that I wish to publish like abcd.c file based on the GET parameter (normal php coding).
ex. http://www.mysite.com/othercontent/index.php?file=abcd.c
Gotta becareful to allow index.php file to read only permitted content and not to allow index.php file to go into .. folders etc.
December 14th, 2009 - 00:23
You my friend, are an absoloute legend!
I love you, and want your babies.
Problem is im a guy and im assuming you are too, however…a beer your way is more than well deserved.
December 14th, 2009 - 08:52
Karl, thanks for your comments. Glad it helped you.
August 19th, 2010 - 06:53
I had a similar need WP+WHMCS but your steps did not work for me. Turns out any explicit JS that was in my WP page header or body, would make the WHMCS pages not display in IE. Do you know why is that?
So then, since I could not just use the WP code as is, I went the manual route and created a blank page in WP, copied the HTML code and pasted the top part in WHMCS’s header.tpl and bottom part in footer.tpl. Tehn painstakingly had to insert the WHMCS markings that were originally there (saved for reference as header-original.tpl and footer-original.tpl).
Took a while but it is working well now. Since it is all custom, I decided to leave out the WP main menu bar and links from the footer. This way I will not have to update (since it is a manual process) if it changes but is also good not to have those distracting links when the customer is on the WHMCS order pages…
Makes sense? Let me know if you have any additional feedback on this…
Thanks!
August 24th, 2010 - 19:36
http://wordpress.org/extend/plugins/templatesync/
There you go people; Its a half way house. It stops you from iframing, and when used correctly, you have a one click update to sync the headers and footers.
WP 3.0.1 compatible.
It is NOT plug and play – you’ll stil need toget your hands dirty.
September 10th, 2010 - 16:07
Thanks so much !
December 27th, 2010 - 23:33
i have an issue thats taking me too long to figure out..
i have installed wp ” siteroot/blog”
i’m trying to change the “php get footer” on the bottom of the wp index.php to instead link to a footer.php i’m using throught my entire site which is located on the root of my main site
eg
/blog
/images
/myheader.php
/myindex.php
/myfooter.php
Ive tried “”
and also tried it as an absolute link.. doesnt work
January 31st, 2011 - 21:00
hi there,
im trying to make a normal php file include the wordpress header and footer so it looks like part of a site.
i created a test.php file on http://www.pcnetwork.co.za as follows:
<?php
require('./wp-blog-header.php');
get_header();
print "hello";
print "”;
print “”;
get_footer()
?>
works perfectly
but i want to do this from a external server so i changed the path to the path of the server eg
include(‘http://www.pcnetwork.co.za/wp-blog-header.php‘);
this however throws an error:
Warning: include(http://www.pcnetwork.co.za/wp-blog-header.php) [function.include]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /var/www/intranet/test/test.php on line 12
Warning: include() [function.include]: Failed opening ‘http://www.pcnetwork.co.za/wp-blog-header.php‘ for inclusion (include_path=’.:/usr/share/php:/usr/share/pear’) in /var/www/intranet/test/test.php on line 12
Fatal error: Call to undefined function get_header() in /var/www/intranet/test/test.php on line 13
ANY suggestions would be great.
thanks.
David.
April 30th, 2011 - 09:24
Thanks for the tutorial, im using it to integrate my WP site with a hosting control panel
June 2nd, 2011 - 19:51
Hi
has anyone worked out an answer to this.
Im still struggling. would like to find a way besides for saving the website as html via a browser and then including the html file with the wordpress css.
Need to do this from another server.
Please advise
Thanks
http://www.pcnetwork.co.za
http://www.networkcabling.co.za
July 18th, 2011 - 00:28
I am sorry,
this variant does not approach me.
November 9th, 2011 - 23:12
I don’t have shell scripting access on my host. Any other way to dynamically wrap a header around phpbb would be helpful!
November 28th, 2011 - 01:30
After spending a few day looking for the best solution to this common request, I found it!!
There is a great plug-in available now called Template Sync.
Basically you add a couple bits of code to your header.php and footer.php, then hit a button and shazam, a html version of the files is created. from there it is a simple inclufe file in the .tpl files and you’re up and running. If you update any parts, simply hit the button and it generates a new file… wish I found this days ago.