How do I debug a short code?

From reading this guide, could you try using a variable to output the return as such? $output=”This is the return”; return $output; Also, if you’re calling the shortcode with do_shortcode(‘[michael]’); in a php file, you’ll need to echo this, like so: <?php echo do_shortcode(‘[michael]’); ?>

Duplicating Table of Contents for Paginated Post

You split post content into multiple pages with <!–nextpage–>, so you can use $page_number = get_query_var( ‘page’ ) to get current page number and global variable $numpages to get the number of pages in current post. Displaying table of content: global $numpages; $post_link = get_permalink(); $page_number = get_query_var( ‘page’ ); $toc = [ 1=>’Introduction’, ‘I2C … Read more

Passing a nested shortcode as an argument of another shortcode?

A partial solution I’ve found so far is to escape the brackets in the initial call, then replace the escaped characters in the do_foo_shortcode function. function do_foo_shortcode($atts, $content = null) { extract(shortcode_atts(array( ‘bar’ => ”, ), $atts, ‘foo’)); $bar = str_replace(“&#091;”, “[“, $bar); $bar = str_replace(“&#093;”, “]”, $bar); $bar = do_shortcode($bar); $content = do_shortcode($content); return … Read more

Plugin echos text from shortcode function in gutenberg page editor

As Milo noticed, shortcodes should return content instead of echoing it. So change while($query1->have_posts()) : $query1->the_post(); echo ‘<div class=”menu-thumb”>’; the_post_thumbnail( ); echo ‘</div>’; echo ‘<div class=”menu-title”>’; the_title( ); echo ‘</div>’; echo ‘<div class=”menu-content”>’; the_content( ); echo ‘</div>’; endwhile; to while($query1->have_posts()) : $query1->the_post(); $div = ‘<div class=”menu-thumb”>’; $div .= get_the_post_thumbnail( ); $div .= ‘</div>’; $div .= … Read more

How to create shortcode to display custom field value on a custom post type

You’ll have to use add_shortcode to achieve this. Let’s say that you want this shortcode to be called “my_cf”: function my_cf_shortcode_callback( $atts ) { $atts = shortcode_atts( array( ‘post_id’ => get_the_ID(), ), $atts, ‘my_cf’ ); return get_post_meta( $atts[‘post_id’], <FIELD_NAME>, true ); } add_shortcode( ‘my_cf’, ‘my_cf_shortcode_callback’ ); Now you can use it by putting [my_cf] or … Read more