Using WordPress to Supplement Your Existing Web Application

Everyone is pretty familiar with the concept of building an entire website using the WordPress CMS.  But what if you already have a fully developed website that you want to add CMS functionality to without rewriting and restructuring the entire thing?  WordPress is a powerful tool that can allow you to do just that. But first, you will need some basic understanding of how WordPress works and where to draw the line between leveraging WP and frankensteining it.

Right out of the box, WP can be installed in a subdirectory of your website to control that part of your website.  The most common use of this is adding a blog to your website.  (mysite.com/blog) .  But WordPress can do so much more.  Let's look at the WP htaccess code and I'll explain.

.htaccess RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
RewriteRule . index.php [L]

You can see that WP rewrites ANY request that does not match an existing file or directory to the index.php file.  This gives WP a chance to match the requested URL to any of it's internal permalinks using its own routing engine.  What does this mean?  It means that any request that doesn't match one of your existing file or folder names will automatically be picked up by WordPress and return the relevant document.  But what if I already have an index.php file in my existing application?  Not to worry, just rename WP's index.php to something else, ie: wordpress.php and update the corresponding line in the htaccess rules!  To make this work, simply install WordPress into a subfolder of you site as you normally would BUT during setup, change the site root URL from mysite.com/blog to simply mysite.com.  Once that's done, you only need to copy the index.php file from your subdirectory to your root directly (renaming if needed) and edit a single line of code, so it knows where to find the WordPress installation.  Let's say you named your folder 'wordpress', then you would want your index.php and .htaccess files to look like below.

 

index.php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );

.htaccess RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) wordpress/$2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ wordpress/$2 [L]
RewriteRule . index.php [L]

 

But wait, there's more!  Doing the above allows you to dynamically create and modify any page for your website that doesn't already exist but limits you to a single environment.  What can you do if you have different users that should be able to control different portions of your website's dynamic content?  Why you upgrade to WordPress MultiSite of course!  MultiSite allows you to define additional subsites ontop of your existing WP installation.  So, you can have one sub-site for a blog, one sub-site for promotions, and one to control everything else.   


Why would you ever want to do this anyway?  Well that's easy to answer.  A lot of the time when you want to utilize WordPress' CMS features, but you have some non-trivial application code, you end up having to shoehorn your logic into the WordPress framework to make it work.  This solution allow you to keep them completely separate and give you the best of both worlds without forcing WP into something it's not.

Want to Learn More?

This is just a sample of what we can do. We have 15 years of experience working in nearly every technology and industry. Whatever you are doing, we've done it and are prepared to tackle your project. Reach out and we will discuss it with you.