How To: Integrate Non-WordPress Pages in WordPress

Have you ever put together a cool script or page on your own, and then wanted to integrate it into WordPress so it would have the same look and feel as the rest of your site?

Maybe you have a custom survey you put together with PHP, or a web directory, a Job Board, or some other thing that you can’t really do inside WordPress.

Here’s a bit of code that will help integrate your script with your theme, and will also make other internal WordPress functions available to your script:

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

Your page content here.

<?php get_footer(); ?>

Easy enough? Just make sure the require statement points to the correct path of wp-blog-header.php. This example assumes that your script is inside a directory rather than the root (e.g. /myscript/index.php). If your script is in the same directory as wp-blog-header.php, just change the “../” to “./” ans you’re all set.

Whenever your page is loaded, WordPress will be called upon as well, and your theme will be added in around your script. There’s a small chance that WordPress may conflict with your script though, so be sure to test and change any variables and functions that interfere with WordPress’s internals.

  • http://codingcoding.com Nick

    Its interesting to come across this one. Let me try out the code… Thanks!

  • Solid

    Thanks, been looking for something like this. Works like a charm!

  • http://mfirmansyah.com firman

    there is a mistake on get footer function, i’m using wp 2.7 and it works if i write like this : <?php get_footer(); ?>

  • http://www.webmaster-source.com Matt

    @firman: Oops, it seems I made a typo. :) Thanks for pointing it out.

  • Kaaviyan

    I am new to wordpress. Can anyone help me to solve the below issue?

    Currently when an item is checked out from the shopping cart, it is brought to the payment gateway. However, the seller has no visibility on the item order number and who bought them. Seller wanted to add a reference number on the database that can be linked to the order number on the payment gateway. So, how to intergrate the payment gateway with wordpress?

    Thanks

  • http://www.brainofast.com Milind

    Hi friends,
    I am new user of wordpress .
    Actually I have to my site integrate with wordpress means i have to show the blogs into into sites But I need a single login screen and after logged in, users will redirect to a common Control Panel. Presently, I hace two control panel one is my site(which is created into plain php) another one is “wp”(after wp installation.)
    2. Need to register users from the non-wordpress based site. But I don’t how can I achieve the following:

    [A] On registration time, store password in the user table. Please help to create the password with wordpress encrypion.

    [B] How can compare the password with database password on login time?

    3. Where can I find out WordPress Function References?

    I hope that, the comment is active and will help me as soon as possible

  • ilyk2gruv

    I made a page using the code above, put it in a subdirectory and add the “../”. The content I want shows up in the body, but the title says “page not found” and I cannot write over the title with a new title tag. Any ideas?

  • http://www.devarticles.in Arvind K.

    Work prefect! Going a step further i included to show left and right boxes as well. So my new php page content/form (http://www.devarticles.in/tools/subtitlerep.php) is wrapped in the entire WordPress look now and it works great. Thanks for your great post!

  • http://blog.deobald.org/ BlaM

    Yay, exactly what I was looking for.

    Hint: Use the include and then check what your theme files say (usually single.php will do just fine) to see what to do to get the sidebar (which is get_sidebar()) and stuff.

    However: Is there a way to add such pages programmatically – ie. in form of a plugin? For example if I want allow users to upload my plugin, switch it on – and get new page branch /mypluginpages/*

    Flattr +1 :)

  • http://www.nyhtml.com NY HTML Solutions

    It worked great with the Google CSE code embeded.

  • Dustin

    I owe you a beer! I was trying to find a way to allow a rewrite rule to hit a custom PHP page so I could pass “directories” as variables but have the WP theme still be wrapped around it cleanly. After many search attempts I finally hit the right Google search query to find your post. Thanks!

  • http://till.klampaeckel.de/blog/ Till

    You should embed wp-load.php instead of wp-header.php.

    wp-header.php had lots of different (and sometimes random) side-effects for me. E.g. WordPress tried to do a post-loop, but not all the variables are set and this caused actual PHP errors on my non-wordpress page.

    When I switched to wp-load.php all errors vanished.

    • http://www.webmaster-source.com Matt

      It’s been a few years since I wrote this. You’re right, though. wp-load.php is a better option.

      I’ll update the post.

  • Paul

    Thanks for the example! And thank you for supplying the code and a quick and succinct explanation.

  • http://www.howtoearndollars.webs.com Sonu

    Hi Matt,I need to know that how can I integrate big scripts like AMember Pro or anything similar in to my wordpress site? Please guide me little,Will be waiting for your reply…

    Thanks!

    • http://www.webmaster-source.com Matt

      That’s a bit more complicated. I believe AMember has a WordPress plugin—WooThemes uses it for their site, if I remember correctly.

  • http://www.howtoearndollars.webs.com Sonu

    No,I had give an example of the script.Like,if we have to integrate WHMCS in wordpress then how we can do it.I had seen many sites integrated it.Are they creating the same template like their wordpress site & it looks like they had integrated WHMCS in wordpress.Do you have any idea about it?

    Thanks For Reply…

  • http://www.bloggercent.com Nikhil

    Hello Matt,

    It worked fine. But the title of the page is not changing to what I need it to be. The title too is being taken from the header part hence not allowing me to use a different title. what should I do?