Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Genesis: Stop archives from using first attached image as fallback when no featured image is set.
<?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;
}
@MickeyKay

This comment has been minimized.

Copy link

commented Feb 14, 2014

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!

@graylaurenm

This comment has been minimized.

Copy link

commented Aug 18, 2014

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
You can’t perform that action at this time.