在wordpress中查找短代码
H 当在正在加载的页面上找到[slideshow]快捷码时,我希望能够向我的BODY标记添加一个附加类?这可能吗在wordpress中查找短代码,wordpress,shortcode,nextgen-gallery,Wordpress,Shortcode,Nextgen Gallery,H 当在正在加载的页面上找到[slideshow]快捷码时,我希望能够向我的BODY标记添加一个附加类?这可能吗 谢谢当然,这是可能的。将以下代码添加到主题的functions.php中,并将“您的自定义主体类”替换为您要为文章和页面添加的实际类名,并使用[slideshow]短代码 <?php function custom_body_class($classes) { global $post; if (isset($post->post_content) &a
谢谢当然,这是可能的。将以下代码添加到主题的functions.php中,并将“您的自定义主体类”替换为您要为文章和页面添加的实际类名,并使用[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);
太棒了!成功了。我只需要将[幻灯片]更改为[幻灯片放映],因为它有属性。谢谢!