add a CSS id to the body of a page in wordpress

i want to add an animated background to the front page of my website so i use the following plugin but the problem is that i must apply an id to the body and i don’t know how can i do it in the right way, can anyone help me with that ?

<body id="UNIQUE_ID_HERE"> </body>

P.S :i’m using a child theme

5 Answers
5

Put this in your functions.php →

<?php 

function body_id_dynamic() {

    if (is_home()) {

        echo ' id="home"';

    } elseif (is_single()) {

        echo ' id="single"';

    } elseif (is_search()) {

        echo ' id="search"';

    } elseif (is_archive()) {

        echo ' id="archive"';
    }
}
?>

and then this →

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

P.S. → More customization is possible. This was to give you a clue. Add as many conditions as you want.

Leave a Comment