Image Shortcode from ACF ID

It’s because you have forgot to use $atts[‘post_id’] please find below code. function acf_featured_item_shortcode( $atts ) { // Attributes $atts = shortcode_atts( array( ‘post_id’ => ”, ), $atts ); $post_id = $atts[‘post_id’]; $image = get_field(‘featured_item’, $post_id ); $size=”medium”; // (thumbnail, medium, large, full or custom size) if( $image ) { $output = wp_get_attachment_image( $image, $size, … Read more

Shortcodes: closing shortcode not being processed

The reason echo do_shortcode(“[/expand]”); is not working is because [/expand] is not a valid shortcode on it’s own. The combination of [expand] and [/expand] is valid so echo do_shortcode(“[expand] some content [/expand]”); should work as intended. If you want to use this way of seting things up <?php echo do_shortcode(“[expand]”); ?> content <?php echo do_shortcode(“[/expand]”); … Read more

Adding a class to shortcode API

If it really is just for one page you could use a conditional on the_ID(); from within your shortcode class (it is a custom shortcode right?) $class = the_ID() == 213 ? “some-other-class” : “”; $myhtml = sprintf(“<div class=”some-class %1$s”>%2$s</div>”, $class, $content); The other option is to add parameters or “attributes” to your shortcode as … Read more

Favorite websites with shortened hyperlinks

Sure, you’re looking for the shortcode API. That would enable you to write a short piece of code that does exactly what you want. As easy as this in your functions.php: function wpse246274_wiki( $atts ) { $link = “http://en.wikipedia.org/wiki/” . $atts[‘link’]; return $link; } add_shortcode( ‘wikilink’, ‘wpse246274_wiki’ ); Which you would use like this in … Read more

Shortcode called twice

Shortcodes should never echo; they should always return the text to be displayed. See the User Contributed Notes in the add_shortcode() docs. Your code should read more like this: function displayTable() { $string = ”; $string .= ‘<table>’; $string .= ‘<tbody>’; $fields = get_field_objects(); foreach($fields as $field) { $string .= ‘<td>’; $string .= ‘<td>’. $field[‘label’] … Read more

Custom recent-posts shortcode’s thumbnail image not in line with rest of code

The problem is: the_post_thumbnail() outputs its content immediately. It’s basically like echoing instead of returning. To fix it, you should be able to just replace the_post_thumbnail(‘thumbnail’, [‘class’ => ‘droplet-img’, ‘title’ => get_the_title()]) with get_the_post_thumbnail(‘thumbnail’, [‘class’ => ‘droplet-img’, ‘title’ => get_the_title()])