Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WordPress template snippet to display an image from a CMB file field. Make sure you've registered your CMB field with 'save_id' => true. When the field is saved, the attachment ID will be saved in a custom field and can be accessed by appending _id to your chosen custom field id.
<?php $attachment_id = get_post_meta( get_the_ID(), '_cmb_image_id', true ); ?>
<?php if ( ! empty( $attachment_id ) ) : ?>
<?php echo wp_get_attachment_image( $attachment_id, 'thumbnail' ); ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.