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

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.