Execute shortcodes in PHP
Found it: <?php echo do_shortcode( ‘[your shortcode goes here]’ ); ?>
Found it: <?php echo do_shortcode( ‘[your shortcode goes here]’ ); ?>
I think you should to take a look at the gutenberg bloc. This is not simple at the first approach, but I think you should take a look at it (even if you want to use some plugin to help you) See the doc : https://developer.wordpress.org/block-editor/
It looks like you’re not passing the shortcode attributes to the query arguments at all. Also the arguments array structure a bit wonky. The WP_Query parameter docs is your friend when creating a custom query. Your shortcode should also return its output to show anything. Here’s a modified version of your code that should point … Read more
Use do_shortcode to process any shortcodes inside a string
do_shortcode() returns the content you pass it with the shortcodes, if any, filtered out (ie, processed). So the code you’ve posted in your question won’t work the way you want it to: do_shortcode( get_the_title() ); printf( ‘<h2><a href=”%s” title=”%s”>%s</a></h2>’, get_permalink(), the_title_attribute( ‘echo=0′ ), get_the_title() ); Instead you’ll need to do something more like this: $title … Read more
Yes, shortcode attributes are always strings. WordPress has no way of knowing the intended type of each attribute, and the values are ultimately pulled from an HTML string, after all. If you need $id to be an integer, just do this: $args = ( shortcode_atts( array(‘id’ => ”), $atts ) ); $id = (int) $args[‘id’]; … Read more
First, you’ll have to get shortcode parameter(s). Change function’s declaration to: function display_user_roles( $atts ) { Your shortcode will be either [hw_display_users] or [hw_display_users role=”roletopass”]. The first (no parameter) will use role specified in $args array. Second will replace $args->role with parameter passed. Add if ( !empty( $atts[‘role’] ) ) $args[‘role’] = $atts[‘role’]; before $users … Read more
Shortcodes don’t need to be refreshed, they aren’t cached. Instead it sounds like you have either CDN, page, browser, or database caching. Check for caching plugins that need clearing, and flush any CDN caches you might have.
As Tom J Nowell noted in the comments, your setup is bit wonky, which is why it won’t work. You need to add the ajax actions and register the shortcode earlier – i.e in a custom plugin or in the theme functions.php. This is related to how WordPress handles requests and in which order it … Read more
First, I will add here 3 resources for learning most of the things you need about shortcodes: Official WP Docs A good article Another article that I wrote The idea is that you don’t echo the content in your shortcode, but you return it so that WordPress can only print it where it is needed. … Read more