I know that you can achieve the same by using global variables, but this is also one of the ways to add custom class depending on which page template has been loaded (you would add this into functions.php):
1 2 3 4 5 6 7 8 9 10 |
function add_new_class(){ if (is_page()) { return "page"; } elseif (is_single()) { return "post"; } else { //add other elseifs } } |
While inside page template, you would use something like:
1 |
<header class="entry-header <?php echo $new_class = add_new_class(); ?>"> |
The final result would be:
1 |
<header class="entry-header post"> |
or something like:
1 |
<header class="entry-header page"> |
I’ve also posted this as an answer on Stackexchange, so if you find this useful, do not hesitate to vote me up :).