admin管理员组文章数量:1287270
How can I check if the current shortcode is being used in a widget? I need to disable some shortcode options that are not allowed in a widget.
Someone know how?
How can I check if the current shortcode is being used in a widget? I need to disable some shortcode options that are not allowed in a widget.
Someone know how?
Share Improve this question asked Mar 4, 2016 at 23:31 CytoCyto 112 bronze badges1 Answer
Reset to default 1There are two hooks, widget_text and dynamic_sidebar_params. You can use one of them.
add_filter( 'widget_text', 'wpse219770_filter_widget_text', 1, 3 );
function wpse219770_filter_widget_text( $widget_text, $instance, $widget )
{
$tag = 'bartag';//shortcode tag
if ( 'text-2' == $widget->id && has_shortcode( $instance['text'], $tag ) )
remove_shortcode( $tag );
else
add_shortcode( $tag, 'bartag_func' );
return $widget_text;
}
Or you can use this methode:
add_action( 'dynamic_sidebar_params', 'wpse219770_dynamic_sidebar_params_hook', 1, 1 );
function wpse219770_dynamic_sidebar_params_hook( $content )
{
//print_r( $content ) and use it for conditional
$tag = 'bartag';
if ( shortcode_exists( $tag ) )
remove_shortcode( $tag );
return $content;
}
本文标签: Check if the current shortcode is being used in a widget
版权声明:本文标题:Check if the current shortcode is being used in a widget 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741233041a2362460.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论