Skip to content

Instantly share code, notes, and snippets.

@azeemhassni
Last active August 29, 2015 14:02
Show Gist options
  • Save azeemhassni/92f2b74c49239864d620 to your computer and use it in GitHub Desktop.
Save azeemhassni/92f2b74c49239864d620 to your computer and use it in GitHub Desktop.
Recognize wordpress template .
<?php
/**
* @param : $template_name
* @Author : Azi Baloch
* Description : this function will recognize that is the wordpress current page
* using N template or not .
* eg . i want to add body id depending on template then i can use this function
* to check the currently being used template
**/
function is_tmpl($tmpl_name) {
define('DSF' , '/');
define('DSB' , '\\');
if(!isset($tmpl_name))
return false;
$inc = get_included_files();
$tmpl_dir = get_stylesheet_directory();
$tmpl_dir1 = str_replace('/', '\\', $tmpl_dir);
$tmpl = $tmpl_dir1. DSB . $tmpl_name .'.php';
// printr($inc);
if(in_array($tmpl, $inc)) {
return true;
} else {
return false;
}
}
/**
* Example Useage
**/
$bodyID = 'default';
if(is_home()){
$bodyID = 'homepage';
} else if(is_tmpl('songs_list')){
# your template file name should be songs_list.php
$bodyID = 'songshome';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment