I’m building a template for twentyten child theme. I need to add a class in in the template page, but not in other pages.My template inherits the header and footer, so, I can’t change any markup there. How can I add a class in there without adding that class to other pages? Thanks a lot for the help.
1 Answer
You’re probably looking for something like this:
<?php
function add_classes_to_body_class($classes) {
// make sure 'page-template.php' matches your template name
if ( is_page_template('page-template.php') ) {
$classes[] = 'main';
}
return $classes;
}
add_filter( 'body_class', 'add_classes_to_body_class' );
?>
make sure you add body_class()
into your markup. Traditionally it would be in your body tag like so. <body id="foobar" <?php body_class(); ?>>