Wordpress Hack

by David Bradley

You know how it is, you produced your first webpage using straight html code in a simple text editor. You then moved up to version 1 of Homesite, which offered a little bit more such as automatic tags, then a free trial of Microsoft Frontpage sucks you in without your realising just how crap it is.

Eventually, you've got an over-bloated website with dozens of extra pages in vti_cnf folders and the like, tags you really don't know what to do with and a whole stack of fairly decent looking pages that have no centralized theme or template but are getting reasonable traffic by virtue of their age.

Then along comes a far more tech savvy friend who says the magic word - CMS. Okay, it's not a word it's an acronym, standing for Content Management System. With those three little words your hooked.

A single template, pages created on the fly, with dozens of plugins to help you tweak and fiddle with the site for hours on end.

Fantastico!

You open your hosting control panel and, glory be, there's a whole installation section dedicated to loading up a slew of CMS. How fortuitous.

Your friend recommends Wordpress. So, you go for it. Fantastico! Of course, if you don't have Wordpress in your Fantastico collection you'll have to download the full version from the org itself and load it manually.

You load it up, choose and template and start creating static pages, commentable posts, and the rest in a nice neat sub-folder on your site.

But, jings crivens! What about all those old static pages sitting in the root directory? Not to mention you're relatively high-ranking home page?

Is there a nice, simple way to pull those into the CMS fold and unify the site theme without moving them into the sub-folder and doing loads of 301 rewrites to redirect the pages there?

Thankfully, yes, there is. And, more to the point, it's fairly simple to implement, especially if you have standard pages that you can do a "search and replace" on to slot in the following codes


How to convert a standard page into a Wordpress page

  1. First, make a back up of any pages you plan to change, then add this line to the head section of each page you want to re-theme within the Wordpress system on your site.
    <?php define('WP_USE_THEMES', false); require('./your-wordpress-folder/wp-blog-header.php'); ?>
    That calls in the necessary code from the Wordpress folder (obviously change "your-wordpress-folder" to the actual directory name).
  2. Next, decide which components you're going to need for the page. You'll probably want the header from your theme so add
    <?php get_header(); ?>
    Put that near the top after the body tag.
  3. You've probably got a footer in your theme too, so add this to the bottom of the page before the close body tag
    <?php get_footer(); ?>
  4. Then comes a tricky bit. Where to put the sidebar? It depends. Try it just before the footer tag you added in the previous step first. We can come back later and move it if it doesn't work properly.
    <?php get_sidebar(); ?>
  5. Now, smart readers will have noticed you've probably been adding a load of php tags to pages with an htm or an html and that opening these in your browser is just going to display the code without running it. So, there's one final critical step you must take before things will work as planned. Open up your .htaccess file (you know where that is I take it, root folder, no filename just the extension htaccess (don't forget the dot). Make a backup copy. Then add the following line:
    AddHandler application/x-httpd-php .php .html .htm
    and save the .htaccess file. This will then allow the browser to parse the php in pages with the htm and html extensions as well as the php extension.

It took me a while to find out how to do this, but now I have, but then I did, and now it's (hopefully) given my site a new lease of life. The homepage complies with the blog section header and sidebar etc. It means I can create static, but themed pages in the root that are essentially outside the Wordpress blog (like this one) but adhere to the overall site theme.

You will undoubtedly encounter a a few issues as you develop your site in this way. You might need to move the sidebar code to the header section to make it display properly, and some editing of the CSS style sheet is almost inevitable.

Let me know how you get on. I'd muddled through with my site for years, but now that it's working under CMS making changes is so much slicker. The only trouble is I rarely get any real work done these days as I'm constantly tweaking and fiddling with my plugins.