Quick Tip: How To Enable Wordpress Features On Non-Root Pages
Sep 11th '08 3 Comments
Sometimes you have a page you’d like to add your side bar, recent posts or archives on. One problem, it’s not in the same directory as Wordpress. If this page is not in the Wordpress directory, this page will not work. You’ll get an error for every piece of PHP code referring to a Wordpress function. This quick tip will show you how to overcome this issue and have Wordpress features on a non Wordpress page.
For demonstration purposes, let’s edit an imaginary file called “thankyou.php”. This file will be hosted in the root directory on the web server, not in your theme directory in Wordpress. I’d like to include the sidebar on this page, but it keeps erroring out, saying the sidebar function is not supported.
When editing the file you want to display the sidebar on (this case “thankyou.php”), insert this snippet of PHP code to the top:
<?PHP require_once('wp-blog-header.php'); ?>
Yep, that’s it! Of course the location of that file will vary on your current situation, but if that’s the case, just link it accordingly.
Tags: PHP, Quick Tips, WordPress
3 Comments
nice trick - thanks! it works like a charm
i’m wondering how to avoid the display of “Sorry, no posts matched your criteria.” when the script is receiving some $_GET data. I might just simply chuck it down from the theme - but i would like to be sure data stays were they are; something like an unset for $_GET
any advice?
Quite handy. I came across this post by accident and it proved to be something that provided a little consistency on my site.
Thanks for the easy tip.
6:34 pm
[...] the original: Quick Tip: How To Enable Wordpress Features On Non-Root Pages – Alex Coleman Design Comments0 Leave a Reply Click here to cancel [...]





Subscribe to Main RSS feed