Search code examples
phpwordpresscss-selectorscustom-wordpress-pages

Wordpress - add class to a main div in specific page


I have a certain page where I need just to change background color only in that page and this page structure starts like:

<body class="...">
   <div class="start-class">
      ......
   </div>
</body>

and I was thinking to put in functions.php like:

add_filter( 'body_class', 'my_css');
function my_css( $classes ) {
     if ( is_page(82) )
        find div that has specific "start-class" because it doesn't have any id
          $classes[] = 'my-custom';
 
     return $classes; 
}

is there a way to add it?.. thanks to all!! Cheers!


Solution

  • At the end I decided to apply total transparency on all levels of container elements inside body with:

    background-color:rgba(0,0,0,0.0) !important;
    

    wherever applicable so I could use just a background inside body with that add_filter( 'body_class', 'my_css'); I said in the post so that makes my life easier... thanks to all anyway @Johannes , @Broe , @Rahul Srivastava ! Cheers !!!