enqueue script with get_shortcode_regex

There’s already a function for checking if a post has a shortcode: has_shortcode(): function enqueue_script_if_shortcode_is_detected() { global $post; wp_register_script( ‘leweb-widgets’, get_stylesheet_directory_uri() . ‘/includes/leweb-widgets.php’, ‘1.0’, true ); if ( has_shortcode( $post->post_content, ‘leweb_suggested_events’ ) ) { wp_enqueue_script(‘leweb-widgets’); } } add_action( ‘wp_enqueue_scripts’, ‘enqueue_script_if_shortcode_is_detected’ ); Just keep in mind that checking the post this way: Will not know if … Read more

How to add shortcode to html widget

First thing you need to do is drag & drop a Text widget to your WordPress sidebar on the Appearance » Widgets screen in your dashboard. After adding the widget, you can simply add your shortcode inside the text edit area of the widget.

Variables not showing in short code

Try this: function banner_shortcode() { $banner = esc_url( get_stylesheet_directory_uri() . ‘/images/banner.jpg’ ); $banner__feature = esc_url( get_stylesheet_directory_uri() . ‘/images/banner__feature–easter.jpg’ ); return ‘<div class=”banner banner–call-now” data-parallax=”scroll” data-bleed=”100″ data-image-src=”‘ . $banner . ‘”> <div class=”banner__left”> <img class=”img-responsive” src=”‘ . $banner__feature . ‘”> </div> <div class=”banner__center”> <h2 class=”banner__title”>Call Now!</h2> <h1 class=”banner__phone”><strong><a href=”tel:1-570-877-8595″><strong>570-877-8595</strong></a></strong></h1> </div> <div class=”banner__right”> <img class=”img-responsive” src=”‘ . … Read more

How to parse a shortcode within a shortcode?

The function you are looking for is named do_shortcode (there will also be a function apply_shortcode in WordPress 5.4 that does the same). Codex Page For your example, this will work: function content_for_logged_in($atts,$content){ $logged_in_content = “”; if(is_user_logged_in()){ $logged_in_content = do_shortcode($content); } return $logged_in_content; } add_shortcode(‘logged-in-content’,’content_for_logged_in’); Happy Coding!