Running WordPress Queries in Non-WordPress Pages

At times you might want to run the WordPress queries or wordpress functions in the page located outside the wordpress templates.

Thanks to wordpress for providing a very simple solution to this.

You just need to include the file called “wp-load.php” in the non-wordpress file before calling any WP functions and then you can run wordpress queries or call any wordpress function in that page.

wp-load.php is located in the root folder of your wordpress installation.

eg. if you have installed wordpress in your domains root folder, wp-load.php will be there in your public_html or httpdocs folder as applicable.
if you have installed wordpress in a folder say wp in your domain root, the wp-load.php shall be located in public_html/wp/ folder.

Include this file in your non-wordpress file using a require statement at the very beginning of the file.

require('../wp-load.php');
This entry was posted in Wordpress, Wordpress Hacks. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *