<?php
$images = get_field('gallery');
$size="full"; // (thumbnail, medium, large, full or custom size)
$rand = array_rand($images, 1);
if( $images ): ?>
<?php echo wp_get_attachment_image( $images[$rand]['ID'], $size ); ?>
<?php endif; ?>
This code should work. array_rand()
return key if second param set to 1 or array with keys if second param > 1
Related Posts:
- ACF Wysiwyg Editor Image srcset for responsive images [closed]
- How to get both image attachment ID and url
- Srcset incorrect with Owl Carousel and ACF?
- Call the cropped image of a custom field in the theme
- Advanced Custom Fields Image Crop
- Generate / attach Image srcsets from ACF Image Field
- How do I disable responsive images in WP 4.4?
- Filtering multiple custom fields with WP REST API 2
- How to import CSV into Custom Post Type custom fields?
- WP 4.4. responsive images browser choosing the “wrong” one
- the_post_thumbnail responsive srcset not populating with custom image size
- How to insert pictures without hard coded dimensions?
- ACF – get fields from group
- Create image formats with different qualities when uploading
- Front end form to create a custom post with preview
- How can I set image sizes and still have responsive images using the srcset attribute?
- update_post_meta and update_field ony working when saving the post
- How to get “Additional CSS Class” for ACF Gutenberg block
- Advanced Custom Fields select field : How to echo the label, not the value? [closed]
- ACF: get_field() returning false [closed]
- Pb with responsive image sizes in WP 4.4
- Generate a excerpt from an ACF-wysiwyg-field
- Responsive Images
- WP 4.4. responsive loads normal image after loading the responsive image
- Why is wp_get_attachment_image_src returning wrong dimensions? [duplicate]
- Adding custom fields to the header.php
- Using Advanced Custom Fields with WordPress and Lightbox
- How to get_terms() only of terms matching an ACF meta value?
- Pods cms and “advanced custom fields” plugin
- Making WordPress Gallery (.gallery-item) Responsive?
- Adding a body class with ACF
- Returning all radio button options when using Advanced Custom Fields
- Featured Image in 4.4 should be larger on mobile device
- WP 4.4 aspect ratio with responsive image
- WP REST API: Order posts by meta value (acf)?
- How to use the responsive images feature from WP 4.4 in your themes
- wordpress REST-API upload image to ACF
- Generating Responsive Background Image Sizes in PHP
- How can I serve different images depending on screen size with wordpress
- Query between dates using Date Picker fields
- Order and group posts by acf by month and year
- Get the label from ACF checkbox [closed]
- Advanced custom field – gallery – display one random image
- How to update a custom post title from a front-end form using ACF fields?
- Custom Taxonomy Images with Advanced Custom Fields
- Showing an ACF field in admin posts dashboard
- Google Places API With ACF [closed]
- Check for the existence of custom field
- automatically set “Featured Image” the same as the og:i that is set in a custom field
- Vimeo thumbnails [closed]
- pre_get_posts filter using numeric meta_query comparison (from dates)
- How to Make WordPress Default gallery responsive on mobile?
- ACF + contact form 7
- wordpress responsive image srcset not working
- Is there a way to export Advanced Custom Fields data?
- Responsive background images added inline
- How to add a custom field to quick edit
- Advanced custom fields – taxonomy terms images [closed]
- ACF Repeater Field, need IF statement for if sub field has content
- Can not create fields in ACF with code
- Responsive Images – Add srcset attributes to custom Images Function
- Gutenberg First Block on Page Conditional?
- Get a list of all image sizes that match aspect ratio of original one
- Using meta_query and custom fields within pre_get_posts to return posts within a numerical range
- Comparing arrays with meta_query in pre_get_posts
- Set default date in datepicker of an advanced custom field
- Advanced Custom Fields plugin : displaying a YouTube video
- Advanced Custom Fields – Check if multiple get_fields exist?
- ACF – Custom fields have dissappeared [closed]
- Error in Validate Field with ACF plugin in WordPress
- How to order by just the Time Field in Advanced Custom Fields
- Using Gutenberg parse_blocks Function With ACF Custom Blocks?
- Query pages for use of a flexible content layout
- WordPress Gutenberg, update post content programmatically
- ACF get field label in custom code
- ACF repeater field with meta_query
- How to exclude an image size from the WordPress srcset
- Random popup image per user with no repeat
- How to add custom fields in rss feed
- Get specific image size for small viewport width
- Responsive Images Resizing Images
- sort by date in Advanced Custom Field
- Get specific repeater row (via advanced custom fields) based on Meta Query with Wildcards [closed]
- How to customize a divs background dynamically using Advanced Custom Fields Plugin?
- Get full image array
- disable (read only) a field if within a custom post type name
- How to update custom taxonomy meta using ACF update_field() function or any other wordpress function
- Replace post’s “the_content” with ACF value
- ACF if / else checkbox [closed]
- PHP echo stripping formatting in Advanced Custom Fields [closed]
- Thumbnails generated from PDF in the “Media” section – how to show them in theme template?
- Post Object field orderby (Advanced Custom Field)
- How to count ACF Flexible Content Rows?
- GIF featured image is resized on server but not used in frontend. Why?
- How to change the page title from functions.php
- Sorting custom admin column by value
- Featured image (responsive) above content is too small after update to WordPress 4.4
- Acf Pro repeater field returns null [closed]
- Query between dates using date picker filter breaks in WordPress 4.2.1
- How to upload multiple images on frontend to ACF gallery using update_field