How to not show shortcode contents if cart is empty?

You can check the carts content then show the cart if it has some items // Add a WooCommerce Cart Total shortcode [cart_total] add_filter(‘woocommerce_add_to_cart_fragments’, ‘woocommerce_header_add_to_cart_fragment’); function woocommerce_header_add_to_cart_fragment( $fragments ) { global $woocommerce; ob_start(); ?> <a class=”cart-contents” href=”https://wordpress.stackexchange.com/questions/274073/<?php echo $woocommerce->cart->get_cart_url(); ?>” title=”<?php _e(‘View your shopping cart’, ‘woothemes’); ?>”><i class=”fa fa-shopping-cart “></i>&nbsp;<?php echo $woocommerce->cart->cart_contents_count;?></a> <?php $fragments[‘a.cart-contents’] = … Read more

Custom Shortcode with Dynamic Button

This may not be a direct answer to your shortcode issue. But try doing it as a post template, from there its easier to handle post data. You have a working button below the description. Copy it and place it on the bottom. And use Class to trigger your JS this time.

If do_shortcode is blank, return some message

From several version of WordPress, it’s better to use https://developer.wordpress.org/reference/functions/apply_shortcodes/ io do_shortcode. That said you can surely do something using has_shortcode() https://developer.wordpress.org/reference/functions/has_shortcode/

loop on page makes shortcode fail

You really shouldn’t use query_posts() for anything other than the main loop of that page and use either WP_Query() or get_posts(), try this: $my_query = new WP_Query( array( ‘category_name’ => ‘interesting_sites’, ‘posts_per_page’ => 3, ‘orderby’ => ‘rand’ ) ); while ($my_query->have_posts()){ $my_query->the_post(); ?> <div <?php post_class(); ?>> <h1><?php the_title(); ?></h1> <?php the_content(); ?> </div> <?php … Read more

How to attach sidebar to shortcode’s output?

I’m still not sure exactly what you’re trying to do, but here’s one possibility if it’s to display something like this: PAGE CONTENT | SHORTCODE/POSTS LOOP | SIDEBAR Do you have control of the shortcode content? If so, you could update it so its output is wrapped in a <div id=”shortcodecontent”> –shortcode post-loop output– </div>. … Read more

Can’t get default values to work with custom shortcode

extract takes and associative array and explodes it out in variables that reflect the array key names. $atts[‘height’] would just be $height, in other words. The relevant two lines of your code would become: <param name=”type” value=”video/quicktime” height=”‘.$height.'” width=”‘.$width.'”> <embed src=”‘.$url.'” height=”‘.$height.'” width=”‘.$width.'” autoplay=”false” type=”video/quicktime” pluginspage=”http://www.apple.com/quicktime/download/”> If you did still want to use the indexing, … Read more

Shortcode Variations?

function btn($atts, $content = null) { extract(shortcode_atts(array(‘link’ => ‘#’, ‘color’ => ‘teal’ , ‘size’ => ‘large’), $atts)); return ‘<a class=”btn ‘.$size.'” href=”‘.$link.'” style=”background:’.$color.’;”><span>’ . do_shortcode($content) . ‘</span></a>’; } With that function you get by default color teal and size large. I suppose that for size you are using classess and for color just background. If … Read more