<body <?php body_class(); ?> >

In header.php I have written the above code.

But I want when this page template is in use:




class should go above. Is this possible through some hook?


1 Answer 1


there is a filter for that and it's called... body_class ;) This should work for your case:

function add_my_custom_body_class( $classes ) {
    if ( is_page_template( 'page-customer.php' ) ) {
        $classes[] = 'body_customer';

    return $classes;
add_filter( 'body_class', 'add_my_custom_body_class', 10, 1 );

if you wanna add class based on page ID (as you've mentioned in comments), you can change the logic inside the function and add class only when particular page is queried, let's say your page ID is 3:

if ( 3 === get_the_ID() ){
     $classes[] = 'your_additional_class';
  • Thanks I was interested in adding based on page template only. Thanks for the help.
    – WordCent
    Commented Sep 2, 2018 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.