H
当在正在加载的页面上找到 [slideshow] 短代码时,我希望能够向我的 BODY 标记添加一个附加类?这可能吗?
谢谢
H
当在正在加载的页面上找到 [slideshow] 短代码时,我希望能够向我的 BODY 标记添加一个附加类?这可能吗?
谢谢
当然,这是可能的。将以下代码添加到主题的 functions.php 中,并将“your-custom-body-class”替换为您要为带有 [slideshow] 短代码的帖子和页面添加的实际类名。
<?php
function custom_body_class($classes) {
global $post;
if (isset($post->post_content) && false !== stripos($post->post_content, '[slideshow]')) {
array_push($classes, 'your-custom-body-class');
}
return $classes;
}
add_filter('body_class', 'custom_body_class', 100, 1);