I use a really simple MVC framework that I’ve developed over the years to create many of the websites I’ve built. I recommend that my clients have some portion of their site that is updated frequently with new relevant text. Sometimes I use WordPress to handle the blog portion of the site. WordPress provides a nice user interface for creating new content, managing comments, and is relatively simple to make search friendly. In most cases, I like to include portions of WordPress generated content outside of the blog itself. We’ve even done this on our own Industry Forge website.
I thought there might be a simple way to include the WordPress functions I needed outside of WordPress. I went to Google and searched for “show wordpress posts outside of wordpress.” I found a few articles on how to include the wp-blog-header.php file from WordPress to give your php script access to all the WordPress functions. They all provided a bad solution:
Wrong Way to Include WordPress Functions In Your Site
This seemed to be a pretty simple way to get what I wanted quickly. I was happy with the solution for a few days until I saw the 404 errors begin to show up in my Google Webmaster Tools account for this domain. I was a little perplexed that Google had been picking up 404 errors from pages that actually existed. You don’t want your site to throw 404 errors on pages that actually exist. It’s not search engine friendly at all (even though users don’t know the difference unless they’re closely examining all the headers received by their browser). I realized that this method was not the right choice for me. It was not search engine friendly at all, and would cost me big-time in my own SEO efforts.
It turns out that since I was loading the wp-blog-header.php file before loading any of the rest of my own framework, and because WordPress could not find the specific requested page in its database it sent a 404 header. I verified this with the Live HTTP Headers add-on for Firefox. I never intended for WordPress to actually handle the delivery of the page—I only wanted a few of the recent blog posts—but how was WordPress to know that? Its built to be a full CMS system (I know, I should rethink using it this way). But wait! There is a simple fix.
The Simple Fix
I did a bit of poking through the massive WordPress codebase this morning looking for all the lines the would produce a 404 error. Of course after just a few minutes I thought, “what am I doing? Certainly some astute web developer has had this issue before and has likely posted a solution on his or her blog.” I was right. Thanks to a writing style much more succinct than my own, I was able to look at the post by the nice folks at Adrogen (a Denver website design company) and quickly implement the solution they offer. They suggest using the following 5 lines of code to include WordPress instead of just including the entire WordPress framework:
Correct Search Engine Friendly Way to Include WordPress Functions In Your Site
Thanks, Adrogen. You saved me a lot of headache and a lot of illegitimate 404 errors being sent to Google.