There may be a time when you’ve added WordPress on to an already existing site, to perhaps power the news section or to just provide a blog or multiple blogs for people. If the site is small then it’s usually easier to just convert the existing pages into static pages, and use the CMS functionality of WordPress to power the whole site. However, that may not always be the case, especially with large websites.
Just because your site is external to WordPress doesn’t mean you can’t still include information and content from WordPress on the rest of your site
To do this all you need to do is include the following line of code at the top of any external file where you want to use the WordPress functions:
[sourcecode language="php"]include ‘path-to-wp-directory/wp-blog-header.php’;[/sourcecode]
The path to your wordpress directory needs to be relative to the page with the include in. The file wp-blog-header.php is in the root of your WordPress installation. Calling this file will automatically set the database connection to your WordPress install, and allow you to make use of any built in functions or plugin functions.
With this at the top of all pages it allows you to include additional information from WordPress such as
- List your Recent Posts
- List your post categories/tags or a tag cloud
- List the Authors on the Blog
- List the post archives
If you are just using WordPress to power your news section then the last option above could be useful. You could display perhaps the last 3 months using the limit parameter eg.
[sourcecode language="php"]< ?php include 'path-to-wp-directory/wp-blog-header.php'; ?>
News Archives
-
< ?php wp_get_archives('type=monthly&limit=3'); ?>
[/sourcecode]
You can also include plugin functions, so you could display the recent comments on your news items or blog posts, or make use of any other useful plugin that you may have installed.








Thanks Sarah, very helpful! Are there any wordpress functions that will not working outside of wordpress? What about widgets in your wordpress sidebar?
Hi Greg, I've never tried widgets externally as I don't use them, however as they're loaded via function (ie. dynamic_sidebar()) then I don't see why not. Easiest option is to give it a go and let us know
Thanks for this. Could prove really useful for a project I'm working on
Hi is this similar to when … for example I use BP custom community theme and would like to use the bp-p2 theme functions.php file to power my index.php? Forgive me but I don't know any PHP language
VERY VERY VERY useful THANKS!
Now i can finaly access wordpress function from exterlan php file. Thank you very very much.
My recent post Trafiku i organeve- BE ngre Task Forcë- HRW- Duhet një prokuror i zoti