Home » CubeCart, PHP, Wordpress

Using Wordpress header and footers externally

Submitted by Kieran on Wednesday, 24 September 2008One Comment

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.

Heres 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/YOUR_THEME/header.php";
?>

and footer-wrapper.php looks like this

<?php
require('./wp-blog-header.php');
 
include $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/YOUR_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

{include file=”/home/YOUR_PATH/header-wrapper.html”}

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:

  1. Single Line Wordpress Install
  2. CubeCart and Wordpress Integration
  3. Site Performance Quick Fixes
  4. Converting XLS to CSV. Simple, eh? Well, sorta.
  5. Extra Cover Cricket

One Comment »

  • srednarb said:

    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.

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.

Related Posts


Fatal error: Call to a member function have_posts() on a non-object in /home/blokeor/public_html/wp-content/themes/arthemia-premium/single.php on line 110