Answer the question
In order to leave comments, you need to log in
How to check for template-name and set class for body?
Good afternoon. Made page templates template-name.php and created pages by selecting the desired template. Body and, accordingly, header are loaded from header.php, however, for each body, the layout designer set a specific class that is needed for CSS. Now I need to set the check if( is_name == name-template) { class body = "template-name class"} . (I think I explained clearly). But I don't know how to get the template name into a variable and set the class. Prompt please
For an example I will set a following.
the file is called template-faq.php
<?php
/*
* Template name: Template FAQ
* */
?>
Answer the question
In order to leave comments, you need to log in
Wordpress has the is_page_template() function. For example, is_page_template('templates/contact.php') if this file is used to generate the page, then the function will return true.
I did something similar, here's an example:
<?php
function custom_body_classes() {
if ( is_front_page() ) :
$classes = body_class();
elseif ( is_page_template('templates/contact.php') ) :
$classes = body_class('contact_mod');
elseif ( is_page_template('templates/projects.php') ) :
$classes = body_class('inner_2_mod');
else :
$classes = body_class('inner_mod');
endif;
return $classes;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question