WordPress templates on non wordpress pages

I have a couple pages such as my password generate that are non wordpress templates. However I want these to be styled as if they where from my wordpress. So after some google searches, I came up with very little information. I decided to dive into the code and came up with something that works for what I need it to do and requires little code edits to any of my pages to work.

This does also require a template edit to your wordpress templates. Sadly I couldn’t avoid this, I looked around and tried to see if I could modify the_content(), however it doesn’t look very pleasant to do so. I might in the future look into doing this. If somebody has a better solution that requires no wordpress template edits, please let me know. Back on topic, I modified page.php in my template and changed:

To this line:

Next I will just dump a file I named wp-ssi.php and explain how it works at the end.

Now for all my files I add at the very top. Of course, you need to substitute the path to match yours.

As for wp-ssi.php, I will can explain more about how that works.

Our first bit of code, simply is a option, nothing more nothing less. It just lets me define the default template, in this example code I used page, however for my theme I customized the page template to display full width and not have the sidebar.

This is the most important piece of code, without it this wouldn’t work. This registers with php a function to run at the end of page execution. I may of been able to use ob_start with a buffer function, but I avoided it.

This is simple, we are turning on a output buffer. I don’t need any buffer replacements, so I just call the function.

This gets wordpress going. This same piece of code is used to start wordpress in the index.php

Consolidating some lines here, we are creating a new function called ‘do_wp_ssi_wrap’. We also used ‘do_wp_ssi_wrap’ in the argument lines with our register_shutdown_function a few lines up. This is the shutdown function that is going to do some stuff before php exits and sends all contents to the browser.

We are capturing all output sent to the buffer at this time. Any output our script has sent is now in a easy to use variable.

Some more overrides here. I simply setup a way to override the theme, otherwise it uses wordpress functions to get the path to the current theme in use. The next one allows me to override the template. Both of these may come in handy if I have a page I want a different theme on or if I want to use a different template on it.

This is simply just including the template from the theme we selected. Oh and the closing function curly bracket. That is all the code needed here.

Leave a Reply

Highslide for Wordpress Plugin