alex
alex

Reputation: 490233

How to add extra classes to Wordpress's body element?

In the default Wordpress template, there is this in header.php.

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

This echos some useful hooks for CSS and JavaScript. Some example output is

<body class="page page-id-45 page-template page-template-gallery-php">

Is it possible, within the header.php even, to add my own classes in addition to what is there?

Specifically, I'd like to do a quick strstr on $_SERVER['HTTP_USER_AGENT'] and add a class if the device is an iDevice.

I figure I could do it with JavaScript, but still being able to know how to add my own classes would be useful nevertheless.

Upvotes: 0

Views: 1089

Answers (1)

Matt Gibson
Matt Gibson

Reputation: 38238

I believe you can just pass the extra class-name as a parameter, i.e.

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

...which seems to be confirmed here.

Upvotes: 1

Related Questions