Make your existing site work with WordPress

January 19, 2009

One of the big questions you see…well anywhere, really, in regards to WordPress is the desire to integrate it into an existing website. Usually, this is because a business has seen the benefits of adding a “blog” to the site (although most usually use it for “news releases”) and they want it to match their current design, or they want to be able to manage their content easily without going to the extreme of a complete overhaul.

I’m going to tell you how to do this.

It’s actually quite simple – you’d be surprised how easy it is to do. “Adding a blog” is one thing – and if you want your blog addition to match your site, you might as well do the entire thing in WordPress anyway, because that’s what it’s going to require to make it work for WordPress. But if you don’t want to go down that road (and many don’t), you can make them work together quite seamlessly.

You need to start by making them recognize each other. Th tricky part is, most static websites are done in flat, static HTML. But you need your files to be in PHP. The conversion may seem like it would be tiring, but truly it’s not, as long as it’s something your host allows. It means adding a line or two to your .htaccess file, and you do need to find out how your PHP runs from your server.

If your host is running PHP as an Apache module, just open up your .htaccess file and add:

AddType application/x-httpd-php .html .htm

If it’s PHP is being run as CGI (common with Windows hosting, actually, but it’s not necessarily true in all cases):

AddHandler application/x-httpd-php .html .htm

Now you can place PHP code within your .htm or .html files and it will run, without having to convert every single file to PHP. This is also good (although not proven, but it’s thought to be) for SEO – because your pages are already indexed with the .html extension. This means there’s no major change, and things will go on as before.

Once you’ve done that, you need to make WordPress and your static site recognize each other. This is easily done by adding in

<?php require('path/to/wp-blog-header.php'); ?>

to the very top of the pages you want to be recognized with WordPress (it has to appear before anything else). Now, the reason you want to do this is, once that field is included into your static site, you can use ANY WordPress tag that you would use for a WordPress site. You can add commenting availability to certain pages, add a widgetized sidebar – whatever you want to do.

Again, you probably don’t want to go through every single file on your static site, and most likely you’d rather make WordPress recognize YOUR site setup. So the above would require you to add a command to every single page on your site that you’d want to use WordPress tags on (there’s no getting around that), but you can also make it work the other way too – you can make WordPress recognize your already-existing files.

At this point, you have a lot of options. The two sites now recognize each other, and you can “swap spit” between the two fairly easily. Now, you need to decide what direction you’re going to take this. Do you keep the static HTML site with WordPress as an add-on, or would you like to progressively move everything over to WordPress and use it as a content management system? (My vote is always for the latter, but that’s me!)

If you want WordPress to recognize your own stylesheet and layout that currently exists, you can simply connect the header to your existing stylesheet. You’ll need to find the path where it’s housed, and use that path alongside that style.css file within your theme template file. I say “alongside” because there are things that WordPress has in place that I bet your regular site doesn’t, and it’s just a good idea to keep that stuff with WordPress, especially if you are doing a slow conversion to the system.

You’ll also want to edit the theme files down to their bare-bones and make sure it has the same structure and div names as your existing site, so that it’ll take on the correct attributes for your classes and ID’s.

But as you can see, it’s very simple to connect a regular static site to a WordPress installation. once you have the two connecting, there’s all kinds of directions you can go with it.

View Comments

What if your pages are already in PHP?

Then you don’t have an issue. Just add the call to the wp-blog-header.php file to the top of your header include.

Hey Shelly,

Thank you for the great article, I can use this info!! Now, how about taking it a step further and define which tags are needed on the “static” site to just include the bare bones blog and which tags in WordPress I need to edit to get it to bare bones. That read so nice and easy I’m just excited to get it going the easiest way possible. Thanks again!

Sorry, comments are now closed on this post. You may thank the spammers for that one. But if you have any questions, please feel free to email me and ask - maybe it'll make for a good update in a future post. :)