wordpress different styles for different pages

After wordpress 2.8 wordpress themes have a template tag for the body tag which will help theme authors to style more effectively with CSS . Tag is called body_class() this function gives the body element different classes and can be added, typically, in the header.php’s HTML body tag.


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

this will output html will look something like this if it is a contact page.

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

Body class may include one or more following class.

* rtl
* home
* blog
* archive
* date
* search
* paged
* attachment
* error404
* single postid-(id)
* attachmentid-(id)
* attachment-(mime-type)
* author
* author-(user_nicename)
* category
* category-(slug)
* tag
* tag-(slug)
* page-parent
* page-child parent-pageid-(id)
* page-template page-template-(template file name)
* search-results
* search-no-results
* logged-in
* paged-(page number)
* single-paged-(page number)
* page-paged-(page number)
* category-paged-(page number)
* tag-paged-(page number)
* date-paged-(page number)
* author-paged-(page number)
* search-paged-(page number)

For more details of this function check WordPress codex

Leave a Reply

Your email address will not be published. Required fields are marked *