Last active
August 29, 2015 14:02
-
-
Save azeemhassni/92f2b74c49239864d620 to your computer and use it in GitHub Desktop.
Recognize wordpress 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
<?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