Skip to content

Instantly share code, notes, and snippets.

@Mamaduka
Forked from remkus/functions.php
Last active December 20, 2015 22:28
Show Gist options
  • Save Mamaduka/6204839 to your computer and use it in GitHub Desktop.
Save Mamaduka/6204839 to your computer and use it in GitHub Desktop.
<?php
**/
* How to detect is a certain page template is in use.
*
* @link http://www.wupperpiraten.de/2009/12/is-a-certain-page-template-active/
*/
function is_pagetemplate_active( $pagetemplate = '' ) {
global $wpdb;
if ( empty( $pagetemplate ) )
return false;
$result = $wpdb->query( $wpdb->prepare( "SELECT meta_key FROM $wpdb->postmeta WHERE meta_key LIKE '_wp_page_template' AND meta_value LIKE %s", $pagetemplate ) );
if ( !$result )
return false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment