I am the senior developer of a modular PHP Framework system which provides my customers with a Content Management System (CMS), ECommerce system, and a variety of other modules (slideshows, testimonials, forms, FAQs, etc etc)

My framework handles all URLs on the site via an existing .htaccess file and dispatches those URLs to the appropriate module.

One feature of this framework that is very important to the users is the fact that the framework handles the generation of the entire page strutter including navigation, providing a consistent look, feel, and navigation from page to page. It is very important that we keep this.

A number of my customers have requested we add a WordPress module. Is it possible to integrate or "embed" WordPress within an existing PHP Framework and navigation template, so that the WordPress engine parses the URL and performs all approbate actions as it normally would, but outputs only the HTML content for the body of the site, allowing my framework to handle the "template" HTML?

FYI, I am an expert in PHP, but have barely touched WordPress. PHP-heavy answers don't frighten me at all (and in fact would be appreciated, if applicable)

1 Answer 1


WordPress itself doesn't actually produce the complete HTML, just parts of it, and only when the theme tells it to. It leaves the header and body and such up to the theme. So if your theme didn't output a section, then it wouldn't be output.

While WP itself really is a full fledged CMS, you can use it as just a generator for a section as follows:

  1. Make a theme that only outputs the bits you want. A theme can be as simple as a style.css file and an index.php file with a Loop in it. See http://codex.wordpress.org/The_Loop

  2. If you examine WP's main index.php file, you'll see that it does nothing more than define('WP_USE_THEMES', true); and then require('./wp-blog-header.php');. So you can do the same to start up WP and produce the output.

  3. URL handling could be tricky. WordPress expects to live at some "root" URL and to handle (most) URLs underneath it. So it would need to know that root URL in the home and siteurl. Implementing it as a module, if you knew these in advance, then you could pre-define WP_HOME and WP_SITEURL before including it so as to force the issue. See, WordPress' own .htaccess basically routes any URL that does not already exist as a file or directory on the system to the index.php. Then it does its own URL parsing after that, and it knows to subtract the root from that, more or less.

That should probably be enough to get you started at least. The trick is that if you implement it this way, it's not going to work with just any WP theme, you'll have to provide special "section only" themes with it. You may need custom code to disable other things as well, like sidebars, menus, anything that doesn't fit into your design of having WP as only a partial page generator.

  • I'll play around with this and get back to you. Thanks!
    – Josh
    Oct 3, 2011 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.