How to do a check in template-name to set the class for the body?

Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
Good afternoon. Made page templates template-name.php and created a page select the template you want. Body respectively the header and loaded from header.php however, for each body, the coder asked a specific class which is needed if CSS. Now I have to ask the check if( is_name == name-template) { body class = "template-name a class"} . ( I think clearly explained). But I don't know how to get into a variable the name of the template and ask the class. Please tell me
For example, I'm going to ask mark.
the file is called template-faq.php
<?php/** Template name: Template FAQ* */?>

At the beginning of the name
and how to set header.php check if loading this Template
Thanks in advance, I would really appreciate your response
by | 18 views

1 Answer

0 like 0 dislike
In Wordpress there is a function is_page_template(). For example, is_page_template('templates/contact.php') if this file is used to generate the page, the function will return true.
Once done this, here's an example:
<?php\rfunction custom_body_classes() {\rif ( is_front_page() ) :\r$classes = body_class();\relseif ( is_page_template('templates/contact.php') ) :\r$classes = body_class('contact_mod');\relseif ( is_page_template('templates/projects.php') ) :\r$classes = body_class('inner_2_mod');\relse :\r$classes = body_class('inner_mod');\rendif;\r\rreturn $classes;\r}</code>

Maybe not the most elegant solution, but it works
110,608 questions
257,187 answers
40,796 users