Embed WordPress Functions Outside WordPress
April 15th, 2009 by Frank • WordPress Tutorials • 21 Comments
From time to time you need data from WordPress, but should not displayed in the system; they are necessary outside the installation. There are basically two options. Content can be quite easy provide via feed and processed or you gain access to the system. And that is basically very simple and is briefly described here.
In an article about Google News, I have already explained how the data can be accessed, even if the output takes place in the root of the WordPress installation. Basically you can access from anywhere the data. Since WordPress 2.5 it's wp-load.php, alternatively and in older versions you simply use the wp-config.php. In addition, the wp-blog-header.php gets even earlier withdrawn and thus may be more suitable.
The following small example ties the file and output the markup and design of the active theme, therefore I use here the access to the content and settings of WordPress, since I use the functions of WordPress integration. This works, as the wp-load.php build a bridge to all other functions in WordPress is.
<?php require( '../my_wordpress_install_root/wp-load.php' ); get_header(); echo 'new content outside WordPress'; get_footer(); ?>
Depending on where the data is needed, it could be, that the absolute path of WordPress is needed. This can be determined by creating a php file with the following contents, put it in the Root of the installation and call it directly. The output is the path to the file.
<?php echo $_SERVER['DOCUMENT_ROOT']; ?>
This is then used in the require command, and can now, as usual, use the features of WordPress.
Info
- Published in WordPress Tutorials
- Tags: PHP, template tag, WordPress, WordPress Hacks, WordPress Themes
- Comment feed | Trackback URL
- read: 10027 | today: 24
- leave a Comment



Wow, did not know you could do this.
Yes wow, I thought something like this would be possible but did not know how.
When you write: ... and can now, as usual, use the features of WordPress.
Does this mean that regular WP template tags can be used to display posts etc...?
And another question: Is it possible to display the posts of two separate blogs on one page ?
So displaying the posts of blog A besides the posts of blog B. (both separate wp installs and databases)
Thank you for a great post
It would be nice if commenters got an reply on their comment/question
Edwin, for example you can use your header or footer on a non WordPress page. I remember i had on my first website a handcoded homepage and under blog was the WordPress installation. i have used the same technique.
For your second question: i think, it doesnt work. Maybe with WordPress mu, but no clue.
Hi Michael,
Thank you for your reply. I will test this on a coming project.
Interesting to see another solution. I always use a call to the wp-blog-header.php file of wordpress to get the wordpress functionality out of wordpress. Like so in the section:
<?phpdefine('WP_USE_THEMES', false);
require('/wp-blog-header.php');
?>
Do you know of the differences between both solutions and the advantages of each? I assume your solution really just calls the functionality whereas the code above loads everything or so since you have to tell to not use the wordpress theme. But I find it more handy cause I won't have to call the get_header and get_footer stuff. Now need to decide which one to use
All additional informations are much appreciated.
Since WordPress 2.6 you can use wp-load.php. Look in your wp-blog-header.php.
Hi, Michael,
I am trying to get this working, but just don't get it right.
The first part of your example works fine. But the absolute path is given me problems.
I want to display wordpress posts from Wordpress on domainA in a non Wordpress second domainB.
The code '' has been put in file test.php.
When i go to test.php this is displayed: E:\domainA.comA\wwwroot
(wwwroot is the root directory on the server)
How do I place this test.php in the require code ??
Thanks for your reply
Neat. I have always created a separate file with scripts to generate the template. Part of the reason is because I have different page headers for pages outside my blog. But your suggestion is definitely worth investigating.
I used a similar solution which shows you how to turn your template into a Wordpress compliant theme: http://embedwordpress.com
This I assume would offer a similar solution with half the work?
wow, great tips mate, i usually get wp data from feed, i'll try to do this way now, thanks
Silly question...does this mean that it's also possible to invoke Wordpress plugin functionality outside of the Wordpress environment also?
hi there,
nice tips, really like it to mess around with wordpress.
i've used this help to get me some extra functionality in my site.
just as you said in your response; i've got a static html website, if you click on blog in the menu, then you go to the wordpress version of my site.
now i've made 1 single page with every blog entry ever typed, and i'm trying to get the comments on there as well.
weirdly enough the code for all the blog posts is working fine, but the comments simply don't show up, as if the code doesn't work.
any ideas?
cheers, vinnie.
@Daniel - yes
If we have to get the posts from multiple wordpress blogs, how would we require the blog-header.php?
Thanks for the tips man!One question though,will the database connection settings change according to the database details of the Worpress application?Because basically the code loads Wordpress functions which I think also includes it db settings.
So shall I reconnect to my present database after I had used the WP functions to retrieve my db settings to my main site?Just a thought...