Add the WordPress Header and Footer, and Utilise the Features of WP on a non-WordPress Page

It was only a few minutes after posting a link to this page that I received a question on how it was done. It may not look like anything special, and it isn’t, but the whole page was rendered with just a few lines of code. Basically, I’m using the WordPress header and footer, and all the features of the core, outside of traditional WordPress pages.

This code will allow you to create your own random pages while utilising the full features of your WordPress installation. All you’ll have to do is copy the following code into a blank file with a PHP extension. You’ll have to be careful to ensure you correctly reference the wp-load.php WP file.

<?php
require( '../wp-load.php' );
get_header();
echo 'This is content outside of WordPress';
get_footer();
?>

This code will display the WP header, footer and the text, “This is content outside of WordPress“. If you wanted to include basic HTML in your page without the PHP entaglements, you could use:

<?php
require( '../wp-load.php' );
get_header();
?>

This is content outside of WordPress

<?php
get_footer();
?>

In the case of the page I linked to, I use shortcode to dump the contents of a directory onto a screen. I use [listcontents="jplayer" directory="jplayer"]. I’ll provide this code another time.

If you choose to use shortcodes in your non-WordPress page, you’ll have to use the following (remembering that you’re well outside the loop!).

$content = "Content outside WordPress [MyShortCode]";
echo do_shortcode($content);

I hope it was useful.

Note: I’m still undertaking a course that’s consuming a lot of my time… thus the infrequent posts. Thanks for the emails!

First Name:
Your Email Address:
 


If you liked this article, you may also like:

  1. Create a Genesis Page Outside of WordPress
  2. [Shortcode] Easily post an aviation TAF report into your WordPress post or page with shortcode
  3. Prevent WordPress Pages from appearing in Search Results
  4. [Shortcode] Easily post an aviation Metar report into your post or page with shortcode
  5. [Shortcode] Include an RSS feed in a post or page with shortcode
About Marty

is a passionate web developer from Sydney, Australia. He owns about 600 websites and makes a healthy living from working the web. As a day job, he works as a pilot for an international airline. Follow Marty on Twitter or Google+.

Comments

  1. Usama says:

    I am using this function in index page outside from wordpress. But It will redirect it to wp-admin/install.php.

    Kindly suggest me some solution for this.

Trackbacks

  1. [...] Some time back I provided code that would permit you to use the WordPress header and footer (and associated functionality [...]

Speak Your Mind

*