Check if the current shortcode is being used in a widget

There 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 … Read more

Extra paragraph tags in an enclosing shortcode

OK, it seems someone has trod this path and there is in fact…. shortcode_unautop() Job Done. It looks elegant in the editor and works in the output. The shortcode now looks like this; function column_shortcode($atts = [], $content = null) { $content=”<div class=”two-column”>”.$content.'</div>’; $content = shortcode_unautop($content); return $content; } add_shortcode(‘two-column’, ‘column_shortcode’);

Custom shortcode is not working in text widget

Shortcodes need to return data, not echo it – use output buffering to capture the output of the include and return it: function related_category_sidebar() { ob_start(); include WP_PLUGIN_DIR . ‘/sabai-directory/assets/templates/template_related_category.php’; return ob_get_clean(); } Then you will also need to do as Charles suggested and enable shortcodes for text widgets: add_filter( ‘widget_text’, ‘do_shortcode’, 11 );

Use shortcodes in custom metabox using wp_editor?

Figured it out: $team_information_value = get_post_meta( get_the_ID(), ‘team_information’, true ); // Checks and displays the retrieved value if( !empty( $team_information_value ) ) { echo do_shortcode($team_information_value); } else { echo ‘Value Not Fount or Empty’; } Put the displayed value (in this case $team_information_value) within a do_shortcode();

Random post + categories + tags

You had it right with categories, just do the same for tags (using get_term_link instead) – better yet, use the core WordPress functions that automatically generate a list of category/tag links: function random_post_shortcode( $atts ) { $posts = get_posts( array( ‘numberposts’ => 1, ‘category_name’ => ! empty( $atts[‘category_name’] ) ? $atts[‘category_name’] : null, ‘orderby’ => … Read more

Plugin shortcodes not working in custom theme

As was pointed out by Michael, I had been missing the wp_head() and wp_footer() functions. To anyone who might be in the same boat as I, you can have a look at the function references here (head) and here (footer). Thank you, to anyone who took their time to help me out, even if all … Read more