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

WordPress Shortcode show database row

I’m not entirely sure if that’s what you wanted, but… Here’s the code that will register a shortcode, which will get given row and output all the fields of it: function shortcode_db_row_cb( $atts ) { $atts = shortcode_atts( array( ‘id’ => false, ), $atts, ‘db_row’ ); global $wpdb; $row = $wpdb->get_row( $wpdb->prepare( “select * from … Read more

Different uniqid when calld in wp_localize_script and shortcode

Inside the __construct() you can put this global $shortcode_id; $shortcode_id = 0; in the display_gallery_shortcode() function you can do this <?php global $shortcode_id; $shortcode_id ++; $settings_arr = array();//Here is your settings for each shortcode ob_start(); ?> <script> if(!my_plugin_data) var my_plugin_data = {} my_plugin_data[<?php echo $shortcode_id ?>] = <?php echo json_encode($settings_arr) ?> </script> <div>MY SHORTCODE CONTENT … Read more

Shortcode to delete post from front end

Following is the reformatted version of your code. get_delete_post_link() is used for fetching delete post URL so that we dont have to worry about nonce stuff. global $post is kept to avoid PHP notice which is currently there in your code. Please check it. function wpso_delete_my_posts() { global $post; ob_start(); if ( current_user_can(‘delete_posts’, $post->ID ) … Read more

Custom Theme, Custom shortcode not working

I would recommend using single quotes if you want to include some HTML, also you need to return something otherwise nothing happens. // WP Shortcode function text_shortcode() { return ‘<strong>bold text:</strong> <a href=”https://wordpress.stackexchange.com/questions/318934/shortcode-returns-escaped-html-tags”>See wordpress.stackexchange.com</a>’; } add_shortcode(‘bold-text’, ‘text_shortcode’); Your WordPress shortcode would be: [bold-text] See my other answers with examples: – Shortcode created to check language … Read more