• Resolved DesignLoud

    (@designloud)


    Hey I am developing a custom theme and I have a question I cannot seem to figure out. I have created 3 custom templates that I will assign to various pages. Each template will have a different background image. I cannot seem to figure out how to append the template name to the body class of those specific templates. Any suggestions of how I can do this? I know I can change them via CSS but I need the body class to match the template so I can use the appropriate selectors. Thanks for the help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • You were so close to the answer when you tagged this topic. You need to use the body_class() function.

    Thread Starter DesignLoud

    (@designloud)

    I already have this in m header:
    <body <?php body_class(); ?>>
    but for example if I go to firebug and try to copy the css path for that body element it returns as body.page rather than what I want which is for it to match the template so if I have three pages using one template I want it to be <body class="template1"> or something of the sort so I can easily style that in CSS and like wise for the other two templates and any pages that use them, like class=”template2″ and so on. Thanks for your help esmi.

    The body_class() function will spit out a whole stack of classes on any given page – one of which will be related to the current applied page template.

    Thread Starter DesignLoud

    (@designloud)

    right, in firebug this is what I get for body classes when I look at the ‘contact page’ which uses the ‘contact template’

    <body class="page page-id-1833 page-template page-template-contact_page-php logged-in admin-bar">

    but I still cannot change that background image to just affect that page template without it affecting other page templates. Even when I try to remove bits and pieces of what wordpress spits out for the body class

    Try styling on body .page-template-contact_page-php.

    Thread Starter DesignLoud

    (@designloud)

    Thanks esmi, after working with it last night I was able to figure it out but it was with your help. Again thanks!

    Glad I could help ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Body class to display template name’ is closed to new replies.