WordPress.org

Ready to get started?Download WordPress

Forums

Setting a body class name (2 posts)

  1. paul448
    Member
    Posted 1 year ago #

    Hi Folks

    I am having a bit of trouble trying to get my head around the following, and was wondering if some can help or point me in the right direction.

    Basically, I have 5 different pages: Home, About, Portfolio, Contact and Blog.

    Each body tag in the original HTML document which I am transferring to wordpress has a different body class eg:

    (Home Page)
    <body home blog>

    (Portfolio Page)
    <body page page-work>

    (Contact Page)
    <body page page-contact-paul>

    How can I keep these original classes and change the <body class="..."> for each different page?

    Would I need to do something in the functions.php file?

    Any help would be greatly appreciated! :-)

    Thanks in advance
    Paul

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    you could add this all to the body tag in header.php;

    example:

    <body <?php if( is_page(array('home','blog')) ) echo 'class="home blog"'; elseif( is_page('about') ) echo 'class="page about"'; elseif( is_page('portfolio') ) echo 'class="page page-work"'; elseif( is_page('contact') ) echo 'class="page page-contact-paul"'; ?>">

    http://codex.wordpress.org/Function_Reference/is_page

    or, in case you are planning to use body_class() you can use a filter function in functions.php of your theme;

    http://codex.wordpress.org/Function_Reference/body_class
    http://codex.wordpress.org/Function_Reference/body_class#Add_Classes_By_Filters

Topic Closed

This topic has been closed to new replies.

About this Topic