Created
October 22, 2012 01:59
-
-
Save Vheissu/3929245 to your computer and use it in GitHub Desktop.
A simple Wordpress function for checking whether or not a page is using any custom page template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A simple function for checking if a page is using a custom template | |
function using_page_template() | |
{ | |
$templates = get_page_templates(); | |
$result = FALSE; | |
foreach ($templates AS $template_name => $template_filename) | |
{ | |
if ( is_page_template($template_filename) ) | |
{ | |
$result = TRUE; | |
break; | |
} | |
} | |
return $result; | |
} | |
// We don't need to do anything if we're in the admin section | |
if (!is_admin()) | |
{ | |
// Sometimes there is an issue with the function not existing, so we define it | |
// if we can't find the default Wordpress function (no harm in doing this) | |
if ( !function_exists('get_page_templates') ) | |
{ | |
function get_page_templates() | |
{ | |
return array_flip( wp_get_theme()->get_page_templates() ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment