How to Use WordPress Functions Outside the Theme Folder
| By Matt Dunlap on September 30th, 2009 | 8 comments |
WordPress has some really good functions and classes that help developing a website quickly. Sometimes you want to make a webpage that is outside your wordpress theme but still use classes like the database class ($wpdb). It is very simple. All you have to do is inlcude the wp-config.php file located in your website root folder into any webpage that you want to access wordpress functions.
I’ve had to use thisĀ in a few different scenarios.
- Writing a plugin where you have some files that are not activated when you activate the plugin. A very simple plugin will have a single file that contains the functions needed to activate the plugin, add the menu items, and do the job of the plugin. What if you are using AJAX and you need to access some data from the database but the file is not the main plugin file. You will need to include wp-config.php for this to work.
- If you make a file in the root folder and include wp-config.php you can then access get_header(), get_footer(), etc… even though you are outside the theme folder. The header for this file and webpage will be the same header as the current selected theme.
This can be used for a webpage located in the root folder.
include('wp-config.php');
global $wpdb, $table_prefix;
//this will now allow you to access the database and if using wpmu, use the table_prefix to access the proper website data




Post a Comment