Support » Themes and Templates » Add new class to page body

  • Resolved zzuum


    I want to add new class on each new page.
    for example:
    When i create new page, i want to add page-slug to class in <body> tag.

    So that page-slug be my new class.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Here si solution:

    //Page Slug Body Class
    function add_slug_body_class( $classes ) {
    global $post;
    if ( isset( $post ) ) {
    $classes[] = $post->post_type . '-' . $post->post_name;
    return $classes;
    add_filter( 'body_class', 'add_slug_body_class' );
    Moderator Jose Castaneda



    WordPress already adds the id to the body class.

    Sort of like:

    <body class="page page-id-124 page-template-default">

    Depending on how the theme functions. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add new class to page body’ is closed to new replies.