Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jan-Willem

    (@janwoostendorp)

    Helo Jackalope Co,

    Sorry for the late replay I was unavailable.
    Do you mean a random image. You can achieve this by the following code.

    function dfi_random_image ( $dfi_id, $post_id ) {
    
    	$image_ids = array (
    		3, // list of image id's
    		4, // list of image id's
    		5, // list of image id's
    		6, // list of image id's
    	);
    
    	return $image_ids[array_rand($image_ids)];
    }
    
    add_filter( 'dfi_thumbnail_id', 'dfi_random_image', 10 , 2 );

    I’m afraid if I add this as a buildin feature the plugin will be more complicated to use.

    Thread Starter Aslan French

    (@thedonquixotic)

    Hey @janwoostendorp

    Thanks for replying. Does that just pick a random image from the media library or does it pick one from the post?

    I had an array of images I wanted to use as filer backgrounds that were saved to my theme. I could also upload them, but wasn’t sure how the code you included here for the function.php file would work with it? Do I upload them and then specify the image ids in the code?

    Plugin Author Jan-Willem

    (@janwoostendorp)

    Yes, the way featured images work is that they require an media/image ID.
    So the best way is upload them. Grab the ID’s and put them in the code.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Feature Request: Provide opition to select at random from a selection of images’ is closed to new replies.