开发者

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

开发者 https://www.devze.com 2023-01-12 23:13 出处:网络
In the default Wordpress template, there is this in header.php. <body <?php body_class(); ?>>

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 i开发者_如何学编程n 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号