Skip to content

Instantly share code, notes, and snippets.

@cornelisonc cornelisonc/after.php
Last active Apr 6, 2018

What would you like to do?
WordPress blog archive: featured image or dynamic random featured image
<div class="list-article-thumb">
<a href="<?php echo esc_url( get_permalink() ); ?>">
if ( has_post_thumbnail( ) ) {
} else {
$images_iterator = new FilesystemIterator(
WP_CONTENT_DIR . '/themes/yourthemename/images/',
$rand = rand(1, iterator_count($images_iterator));
echo '<img alt="" src="'. get_stylesheet_directory_uri() . '/images/' . $rand . '.jpg' .'">';
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.