Skip to content

Commit

Permalink
Added extra support example
Browse files Browse the repository at this point in the history
  • Loading branch information
janw-me committed Sep 16, 2023
1 parent eb808fd commit 3b66c8d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .support/2023-09-16-random.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Plugin Name: Default Featured Image - Random post image
* Plugin URI: https://wordpress.org/support/topic/multiple-featured-images-6/
* Version: 1.0
*/

add_filter( 'dfi_thumbnail_id', 'dfi_random_image', 10, 2 );
function dfi_random_image( $dfi_id, $post_id ) {
if ( get_post_type( $post_id ) !== 'post' ) {
return $dfi_id; // This is not a post, we only check posts.
}
$random_image_ids = array(
123, # Add your image id's in this array.
456,
);

return $random_image_ids[ array_rand( $random_image_ids ) ];
}

0 comments on commit 3b66c8d

Please sign in to comment.