Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在wordpress中查找短代码_Wordpress_Shortcode_Nextgen Gallery - Fatal编程技术网

在wordpress中查找短代码

在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

H

当在正在加载的页面上找到[slideshow]快捷码时,我希望能够向我的BODY标记添加一个附加类?这可能吗


谢谢

当然,这是可能的。将以下代码添加到主题的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);

太棒了!成功了。我只需要将[幻灯片]更改为[幻灯片放映],因为它有属性。谢谢!