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

How to check if do_shortcode will be execute directly in a template php file

I found a solution. First of all, the best way seems to not use do_shortcode direclty in the php. You can know more here. So… taxonomy-mytaxonomy.php <?php defined( ‘ABSPATH’ ) || exit; get_header( ); ?> <!– Content –> <div id=”content” class=”content” role=”main”> <?php the_archive_description( ‘<div class=”taxonomy-description”>’, ‘</div>’ ); if ( have_posts() ) { $queried_object = … Read more

Prevent shortcode from being wrapped in tags

Instead of trying to remove the automatically added paragraphs before or after the fact, you can try removing the wpautop filter from the_content within your shortcode (and re-adding it to maintain consistency for other plugins etc.): add_shortcode( ‘test’, ‘test_sc’ ); function test_sc( $atts ){ remove_filter( ‘the_content’, ‘wpautop’ ); $content = apply_filters( ‘the_content’, ‘$\frac{15}{5} = 3$’ … Read more