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!
3
Answers
At the end I decided to apply total transparency on all levels of container elements inside body with:
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 !!!If you change / add the following php code to your
body
tag in theheader.php
file……, WordPress will automatically add "body classes", among them a
page-id-xxx
, where "xxx" stands for an individual id number per page that corresponds to the page id in the database. Then you can create a CSS rule with abackground-color
for that id (#page-id-xxx { background-color: #abc; }
and add it either to the general stylesheet or via the customizer only to that page.Use below code to add body class for specific pages.
Based on custom class you can change the background color of specific pages.also visit https://developer.wordpress.org/reference/functions/body_class/