Created
October 6, 2011 15:27
-
-
Save byjml/1267681 to your computer and use it in GitHub Desktop.
Conditional WordPress tag to detect page templates when the page is used to display posts, not page content
This file contains hidden or 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
<?php | |
/** | |
* is_custom_page_template() | |
* | |
* This is used to test the current page template when the page template in question is used to display | |
* posts (post archives), not regular page content. The default conditional tag is_page_template() fails | |
* in this situation, so we're using this in-house function instead. | |
* | |
* | |
* @since 0.1.0 | |
* | |
* @global $wp_query WordPress query object. | |
* @param string $template Page template file name (e.g. page-front.php) | |
* @return bool Returns false if page template was not found. | |
*/ | |
function is_custom_page_template( $template = '' ) { | |
global $wp_query; | |
$page_id = $wp_query->get_queried_object_id(); | |
if ( $template == get_post_meta( $page_id, '_wp_page_template', true ) ) | |
return true; | |
else | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment