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, "", array( "class" => "mx-auto d-block" ));
}
return $output;
}
add_shortcode( 'acf_featured_item', 'acf_featured_item_shortcode' );
Related Posts:
- Using ACF field in do_shortcode()
- possibility to control embedded video timeline with buttons and links external to the player
- Problem with using custom shortcode with ACF WYSIWYG field
- Can I wrap an unordered list inside a shortcode?
- Create shortcode in WordPress, using one variable in 3 functions?
- Shortcode default attributes over-riding non-default attributes
- Basic do shortcodes question
- How to Generate html tags using shortcodes?
- Pass fileurl parameter into shortcode from Advanced Custom Fields
- Custom Shortcode + Querying and Ordering Posts using multiple Advanced Custom checkboxes
- Ordering get_terms with ACF not displaying all terms
- Adding a custom field to do_shortcode [closed]
- Shortcode strips formatting and returns at content top
- ACF repeater + group shortcode
- Need help in setting up a transient using API Key and if possible updating it in the ACF field
- Shortcode custom query not passing value
- If statement shortcode
- Use ACF array values in shortcode
- how to add acf value to other plugins shortcode?
- How do I use “while” and “end while” inside of the echo do_shortcode with ACF Repeater?
- How can I hide the ACF shortcode when empty
- How to create a shortcode with 1 parameter (atts)
- shortcodes output before content [duplicate]
- How does a shortcode work?
- WordPress adds br in between my shortcode
- WP_enqueue_script inside shortcode?
- Shortcode to Gutenberg-block: additional text on front-end and conditional display
- template_redirect to accompany with a shortcode
- How navigation works in custom loop within shortcode?
- Tinymce shortcodes within shortcode contents
- How do I preview the result of a shortcode in the TinyMCE editor?
- WordPress shortcode doesn’t working on HomePage
- Why are Shortcodes Disabled in Widgets by Default?
- Add attribute to shortcode dynamically
- Execute shortcode twice in the same page
- How to parse this shortcode?
- Add custom setting that uses radio button to WP Gallery
- Shortcode with hyphen doesn’t work
- Shortcode parsed incorrectly because of heredoc
- Shortcode “post_per_page” not working
- Shortcode is running in page editor
- Creating shortcode with parameter
- Shortcodes won’t work on live environment
- Create shortcode in Child Theme?
- Create a short code to display a specific loop
- How to add shortcode to HTML file (not showing on website)
- Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
- Custom Shortcode: define cursor position/insertion point?
- How to wp_redirect on ‘init’ hook on condition of current post id?
- Buddypress shortcode for tabs [closed]
- How to create an incremental list using shortcodes?
- Do shortcode that is inserted in a textarea is not displaying properly
- How to Make Archive ShortCode
- Adding custom form within add_shortcode
- wp_editor not rendering the shortcode
- how to add shortcode in wordpress container [duplicate]
- How to make this shortcode work for post content wordpress [duplicate]
- stop WordPress removing shortcode from content [closed]
- caption shortcode using image alt as caption
- Is it possible to handle two or more shortcodes in a single page?
- Toggle Shortcode Sanitize Title
- Clearfix Shortcode
- How and when to include shortcode source files
- Use full size images in a specific gallery
- how to create a fav icon shortcode?
- How to deal with WordPress bug: can’t use wrapped and unwrapped shortcode on same post
- Execute Shortcodes when submitting post
- Substituting value via shortcode
- Video shortcode, option are not rendered
- Create shortcode for each form field in contact form 7
- Auto embeds don’t work for attachment descriptions
- Shortcode to appear and show the date not code in Title and description of Social Media sites
- Date Shortcode in Image alt and title tags
- access shortcode atts in template part
- how to add shortcode widget at end of main blog page
- Shortcode result appears above page content
- Shortcode is not showing content when placed in editor (post_type = page)
- How to set up posts per page on WP
- How to insert a short code into Contact Form 7 in WordPress that will call a function once the submit button is pressed
- Unable to make shortcode, what is wrong?
- Multiple shortcodes only use attributes from one of the shortcodes on custom plugin
- How to display a page dependent on a url parameter supplied by a form/button page?
- How do i remove Business feeds Shortcode fatal error
- Push Shortcode parameter to template
- latest posts shortcode with image
- WordPress Gallery with ID’s Shortcode not Working
- Featured image with link to post shortcode, image displaying above the post
- Video shortcode inside tabs shorcode NOT working
- How to stop unwanted splits in excerpts when using shortcodes for sliders or players
- How to add meta slider lite or other slider to main page header in pinboard theme
- Str_replace using shortcode with multiple changes
- Escaping a shortcode so it displays as-is [duplicate]
- WordPress do_shortcode first iteration
- If do_shortcode is blank, return some message
- Add a short code to a plugin
- echo a shortcode in a shortcode code?
- Applying if (get_post_meta) to new shortcode
- Add widget/shortcode to sidebar OUTSIDE of the theme
- How to remove https:// from shortcode generated url
- Shortcode attributes from meta query variables