Define a default Post Thumbnail in Genesis site when there is no Featured Image

If you want to define a default post thumbnail in your Genesis Framework paste below snippet in your function.php file

/** Define a default post thumbnail */
add_filter('genesis_get_image', 'default_image_fallback', 10, 2);
function default_image_fallback($output, $args) {
    global $post;
    if( $output || $args['size'] == 'full' )
        return $output;
  
    $thumbnail = CHILD_URL.'/images/thumb.jpg';
  
    switch($args['format']) {
  
        case 'html' :
            return '<img class="alignleft" src="'.$thumbnail.'" class="attachment-'. $args['size'] .'" alt="'. get_the_title($post->ID) .'" />';
            break;
        case 'url' :
            return $thumbnail;
            break;
       default :
           return $output;
            break;
    }
}

Note: Don’t forget to add ‘thumb.jpg’ in your child theme’s images folder.

Copyright © 2024 Siam Naulak.
magnifiercrossmenu