Sunday, April 8, 2012

What is the WordPress Page Template name displaying?

A nice solution for debugging (custom) Page Template issues in WordPress. When something is wrong, or you're just not sure which Page Template is rendering for the content page. I have found this hack invaluable in my WordPress work, source is here, thanks for the help. This has saved me countless hours while developing and modifying WordPress themes.

Just place the following code in your functions.php

add_filter( 'template_include', 'var_template_include', 1000 );
function var_template_include( $t ){
    $GLOBALS['current_theme_template'] = basename($t);
    return $t;
function get_current_template( $echo = false ) {
    if( !isset( $GLOBALS['current_theme_template'] ) )
        return false;
    if( $echo )
        echo $GLOBALS['current_theme_template'];
        return $GLOBALS['current_theme_template'];
And put 
where ever in your theme files that will display in a comfortable place (usually in footer.php (be careful if you have several custom footers), to display the name of the file.

My first WordPress plugin is live!

It's not much of a plugin, but it solves a problem not only I experienced so in my book it is OK.

Long story:
I wanted to create a demo site for prospective customers conataining all the WrodPress themes I own and can use to build them a site.
I found no easy solution to do this... When I asked in the WordPress question site I got some answers that pointed to a specific plugin

When I checked the plugin, I realized that though it knows how to switch themes live, if you want the theme to support it, some modification needs to be done to the theme itself... Owning over 90 themes (and growing) including premium and free, this was too much work, and a nightmare to maintain. So on with the search for a solution. As the comments on the original thread continued to develop (thank you helgatheviking) I realized the solution was just under my nose... a little more research (this time into plugin coding) and I had a working solution...

Deployed it to my site and the demo site was working like I wanted.

Next step was to upload it to for approval, and before I knew it, I was a published author :-) thanks to WordPress, before long I had the required pages setup on my site, and I was set to go.

Now I'm hooked, and hard at work on my second plugin, which I don't know yet if it will be released under my name, as it is fully sponsored by a commercial company. still a secret... hush...