Last active
May 27, 2017 18:13
-
-
Save GaryJones/7070243 to your computer and use it in GitHub Desktop.
Genesis: Stop archives from using first attached image as fallback when no featured image is set.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Don't include the above. | |
add_filter( 'genesis_get_image_default_args', 'prefix_stop_auto_featured_image' ); | |
/** | |
* Stop Genesis archives from using first attached image as fallback when no featured image is set. | |
* | |
* @param array $args Default image arguments. | |
* | |
* @return array Amended default image arguments. | |
*/ | |
function prefix_stop_auto_featured_image( $args ) { | |
if ( ! isset( $args['context'] ) || 'archive' !== $args['context'] ) | |
return $args; | |
$args['fallback'] = false; | |
return $args; | |
} |
Hey Gary, thank you for this! I modified this code to let me set a default fallback image of my choosing: https://gist.github.com/oncecoupled/1fa7de6b15e862a94b1f
I'm noticing that where my theme does a modified post image and uses genesis_get_image(), the attr and size are not being read in properly for my fallback image, only for my manually set featured images.
<?php
function modified_do_post_image() {
if ( in_array( 'genesis-grid', get_post_class() ) ) {
if ( ! is_singular() && genesis_get_option( 'content_archive_thumbnail' ) ) {
$img = genesis_get_image( array(
'format' => 'html',
'size' => 'half-feature',
'context' => 'archive',
'attr' => genesis_parse_attr( 'post-image' ),
) );
if ( ! empty( $img ) )
printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), $img );
}
}
}
Is there something I'm missing that would make this work for both the set and fallback featured images, or is it not easily accomplished at this time?
Best,
Lauren
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome, been looking for this for a while! Didn't even see it was you until just now, Gary :) Thanks.
I can't for the life of me figure out in what situation 'first-attached' would be a preferred fallback, but this one's been buggin us for ages. Thanks again!