Are shortcode functions applied while rendering the content, or are they executed and stored with the post content?

I don’t know in what exact order filters are applied to the_content(); and whether that’s early enough, but if it doesn’t work for you, I believe it is safe to assume that you’re right in thinking that the shortcode is applied to late. From /wp-includes/shortcodes.php (line 296, wp 3.2.1) it can be seen that shortcodes … Read more

Is it possible to create a shortcode that will query a post based on taxonomies?

here is a simple shortcode that can handle taxonomies, post types and any other parameter that WP_Query takes: add_shortcode(‘posts’,’posts_shortcode_handler’); function posts_shortcode_handler($atts, $content){ extract(shortcode_atts(array( ‘posts_per_page’ => ‘5’, ), $atts)); global $post; $temp = $post; $posts = new WP_Query($atts); $retVal=””; if ($posts->have_posts()){ while ($posts->have_posts()){ $posts->the_post(); // these arguments will be available from inside $content $parameters = array( … Read more

How to handle shortcodes when using the JSON API

You can add your own AJAX API for do_shortcode. Add this to a suitable location (i.e. functions.php or a plugin): add_action(‘wp_ajax_doshortcode’, ‘ajax_doshortcode’); function doshortcode() { echo do_shortcode($_POST[‘text’]); die(); // this is required to return a proper result } And this to your Javascript: $.ajax({ url : ajaxurl, data : { action : ‘doshortcode’, text : … Read more

Can I the caption shortcode to set caption to a data attribute, and with the image’s alignment intact?

Basically the img_caption_shortcode filter allows you to completely replace the default image caption. If you want to do that, you’ll need to ask WP to pass all the argument of the filter to your callback function. <?php add_filter(‘img_caption_shortcode’, ‘wpse81532_caption’, 10, 3 /* three args */); Then your callback will need to take care of all … Read more

Allow shortcode in the author bio textarea

It a matter of using do_shortcode in your author.php template file (or wherever applies). This function has to be “echoed”. And instead of using the_author_meta (which echo‘s the result), use get_the_author_meta. <?php echo do_shortcode( get_the_author_meta( ‘description’ ) ); ?>

Are .MP3 files with capital letter extensions allowed in [audio] shortcode?

No, apparently not. Until this behavior is changed in version 3.7 you can add this filter to your theme’s functions.php file to include additional extensions. Edited: I’ve updated the filter with better code suggested in the comments. Lower case and uppercase extensions function my_custom_audio_extensions( $exts ) { //merge array of upper case extensions with default … Read more

Super simple shortcode not working

Your problem is here: $welcomePage = get_post( 5 ); echo $welcomePage -> post_content; Shortcodes are processed on display by via a filter on the_content which is called by the function the_content(). You’ve bypassed that functionality and are echoing the raw post data. You need to output your code using a proper Loop or explicitly process … Read more

Making Quote Plugin more efficient

Is there more efficient ways to validate the quotes using the WordPress api? I think you should set a nonce for the form You also should check if current user has capability to save quote To get properly sanitize values form $_POST look at filter_input and/or filter_input_array I don’t see performance issues on validation, but … Read more

Can’t understand $atts in functions?

In general, if arguments is not used or the defaults values are to used of an argument/parameter, you don’t have to write it out, they can simply be omitted. The only time when you have to pass any value to an argument is when a function expect a valid value to be passed to it … Read more

Easy way to show excerpts of specific posts on a page

You need a couple of things. A shortcode handler, and a custom query: function wpse_186346_excerpt_length() { return 50; } function wpse_186346_excerpt( $atts ) { $atts = wp_parse_args( $atts, array( ‘posts_per_page’ => 2, // Any other default arguments ) ); // We don’t need paging, always save a query $atts[‘no_found_rows’] = true; // Create query based … Read more