If you want the ability to use WordPress functions/environment features in a section of the website which is outside of the WordPress environment (/blog/wp-content/themes/theme_dir/), then you just need to add the following lines at the top of the PHP page:
1 2 3 4 5
require('../../../../wp-config.php'); $wp->init(); $wp->parse_request(); $wp->query_posts(); $wp->register_globals();
This is usually useful for me and when I install WordPress in a sub-directory, and not in the root, but still want to take advantage of some of the WordPress features.
Note, the relative path to the wp-config.php file will need to be adjusted according to your directory structure. In cases where PHP errors aren’t suppressed, if the relative path is incorrect (i.e. the file cannot be found), an error will be returned.
In any case, add the above code to your PHP page, and you’re good to use WordPress functions, widgets..etc outside of the WordPress environment, or even in a custom file with in the WordPress environment.
This blog post was written on 13 Jun 2013 by Maruf, and has 0 Comments so far
Learning & sharing
This is where we store some of our Web Development thoughts, tips and tricks for both our own uses and for others to learn from. Sharing is caring.
Please feel free to contrinute to our blog posts; perhaps even teach us a few tricks of your own. We'd love to hear your thoughts.