Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active December 21, 2015 23:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/6381350 to your computer and use it in GitHub Desktop.
Save billerickson/6381350 to your computer and use it in GitHub Desktop.
<?php
/**
* Post Image with Fallback
*
*/
function be_post_image_with_fallback() {
if ( ! is_singular() && genesis_get_option( 'content_archive_thumbnail' ) ) {
$img = genesis_get_image( array(
'format' => 'html',
'size' => genesis_get_option( 'image_size' ),
'context' => 'archive',
'attr' => genesis_parse_attr( 'entry-image' ),
) );
if( empty( $img ) )
$img = be_no_thumbnail( genesis_get_option( 'image_size' ) );
if ( ! empty( $img ) )
printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), $img );
}
}
add_action( 'genesis_post_content', 'be_post_image_with_fallback', 9 );
remove_action( 'genesis_post_content', 'genesis_do_post_image' );
/**
* Default Thumbnail
* @author Bill Erickson
* @link http://www.billerickson.net/default-image-for-post-thumbnails/
*
* @param string image size
*/
function be_no_thumbnail( $size ) {
return '<img width="'.get_option($size.'_size_w').'" height="'.get_option($size.'_size_h').'" src="'.get_bloginfo('stylesheet_directory').'/images/no-thumbnail.gif" />';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment