开发者

Wordpress Shortcodes and Conditional Statements

开发者 https://www.devze.com 2023-01-30 09:57 出处:网络
I am using custom shortcodes for my post editor and i now have multiple shortcodes i would like to make a shortode be stylized differently if another shortcode is enabled. Is开发者_高级运维 there a fi

I am using custom shortcodes for my post editor and i now have multiple shortcodes i would like to make a shortode be stylized differently if another shortcode is enabled. Is开发者_高级运维 there a filter or conditional function like is_shortcode('slideshow') if not has anyone written a workaround for this?


There is no API for checking existing shortcodes, but its easy enough to check the global for what has been registered:

<?php
function my_shortcode($atts) {
    global $shortcode_tags;
    if (in_array('other-shortcode', $shortcode_tags)) {
        // ... do conditional logic
    }
}
add_shortcode('my-shortcode', 'my_shortcode');
?>
0

精彩评论

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

关注公众号