在 WordPress 中查找短代码

发布于 2024-12-13 20:05:05 字数 83 浏览 5 评论 0原文

H

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

谢谢

H

I want to be able to add an addition class to my BODY tag when the [slideshow] shortcode is found on the page that is loading? Is this possible?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

第几種人 2024-12-20 20:05:05

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

Sure, it's possible. Add the following code to functions.php of your theme, and replace 'your-custom-body-class' with the actual class name you want to add for posts and pages with [slideshow] shortcode.

<?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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文