user762579
user762579

Reputation:

Wordpress Is there anyway to add specific class to home page body tag?

I am using a theme (Arcade Basic) in which the home page header image is resized differently from all other pages... I would like to have the same header resizing on all pages included the home.. The resizing script is a .js script I don't want (I can't) to modify .

The resizing is triggered by the presence of the 'page' class in the body tag ..

# HOME PAGE
<body class="home blog only-on-home no-fittext basic">

# OTHER PAGES
<body class="page-template-default page page-id-1183 no-fittext basic">

If there anyway to add the 'page' class on the home page ?

Upvotes: 0

Views: 2061

Answers (2)

user7236046
user7236046

Reputation:

Providing that you are using a specific page to act as your homepage and not just the default list of posts, you can add the following is_home() to check if you're on the homepage then add a class.

More information on the static front page setting.

<?php if ( is_home() ) : ?>

    <body class="<?php body_class('homepage'); ?>">

<?php else : ?>

    <body class="<?php body_class(); ?>">

<?php endif; ?>

Upvotes: 1

Stender
Stender

Reputation: 2492

you Can - but I can't say that treating all of your pages like a "page" won't come with bugs.

I would call the class something else.

find this in your header.php

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

Upvotes: 0

Related Questions