Home > AI > Backend > Wordpress >

body_class()

Basic Usage

The following example shows how to implement the body_class template tag into a theme.

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

The actual HTML output might resemble something like this (the About the Tests page from the Theme Unit Test):

1<body class="page page-id-2 page-parent page-template-default logged-in">

In the WordPress Theme stylesheet, add the appropriate styles, such as:

.page {
    /* styles for all posts within the page class */
}
.page-id-2 {
    /* styles for only page ID number 2 */
}
.logged-in {
    /* styles for all pageviews when the user is logged in */
}

Reference:

  • Home page, your body tag will render <body class="blog">
  • Front Page, your body tag will render <body class="home">
  • Blog post detail page (single.php), your body tag will render <body class="single">
  • Page detail page (page.php), your body tag will render <body class="page">

Reference:

https://wordpress.stackexchange.com/questions/125315/style-something-only-on-the-home-page

Leave a Reply