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

Make shortcode’s Bootstrap CSS override the theme’s CSS, how?

Ok, I think I solved: followed this discussion so I imported Bootstrap SASS file in a new SASS file creating a custom class as container to isolate Bootstrap components and compiled the custom .scss to .css. Fixed html and body selector in new CSS file and to have working tooltips I did: $(‘[data-toggle=”tooltip”]’).tooltip({ container: ‘.custom-container’, … Read more

Two different inner shortcode under shortcodes or multiple nesting of inner shortcodes

Yes, you can keep nesting shortcodes. Just keep using the do_shortcode() until the deepest level is reached. https://codex.wordpress.org/Shortcode_API#Nested_Shortcodes So you can do this, [container] [other_column class=”extra-class”] [content] col 1 [/content] [another] col 1-2 [/another] [/other_column] [column] [another] col 2 [/another] [/column] [/container] To achieve output like this, <div class=”container”> <div class=”other-column extra-class”> <div class=”content”> col … Read more

Display first name of logged in user?

The issue here is that both the functions have the same name – colaborator_avatar(). Make sure that $new_user contains the current user. Else use get_current_user_id() like this: get_user_meta( get_current_user_id(), ‘first_name’, true ); Show avatar and first name: // show user avatar if logged in function colaborator_avatar($atts) { if (is_user_logged_in() && !is_feed()) { return get_avatar(get_the_author_meta( ‘user_email’ … Read more

Show history of post revisions on front end

Your shortcode calls wp_list_post_revisions() which echo the output (revision list), hence you get the “updating error”. To fix the issue, you can use output buffering like so: ob_start(); wp_list_post_revisions( get_the_ID() ); $revisions = ob_get_clean(); Or you could use wp_get_post_revisions() and build the HTML list manually. Here’s an example based on the wp_list_post_revisions(): $output=””; if ( … Read more

Create shortcodes within foreach loop (using array)

Solved issue of dynamic function name by using $shortcode var as function name foreach ($shortcodes as $shortcode) { add_shortcode($shortcode, function ($atts) use ($shortcode) { $filepath = str_replace(‘_’, ‘-‘, $shortcode); ob_start(); require_once(get_stylesheet_directory() . ‘/template-parts/’ . $filepath . ‘.php’); return ob_get_clean(); }); }

Convert HTML Script to Shortcode [closed]

Your JavaScript targets a HTML element with the id ‘banner_div’. So the first step is to output such an element in the shortcode. add_shortcode( ‘shortcode_name’, function () { $out=”<div id=”banner_div’></div>’; return $out; } ); Now you need to save the JavaScript (everything between the <script> tags) as a file. This you can now enqueue which … Read more