The default behavior for Tasty Recipes is to assign a recipe thumbnail to each recipe through the recipe editor.
To change this behavior and have the featured image set as the recipe thumbnail (if the recipe doesn't have an assigned image), tech-savvy customers can add a short snippet of code to their theme's functions.php file.
***Before doing this, make sure that you have access to your site's files via FTP (the editor in WordPress is not sufficient in case problems arise) and that you are comfortable with editing your functions.php file. Any minor error in the functions.php file can result in the “white screen of death,” which is easily fixed via FTP but is difficult to fix otherwise (and a nuisance as your site will be unavailable until fixed).***
Place the code below in your functions.php file:
/**
* Uses the post's featured image in the recipe card,
* if the recipe doesn't have an assigned image.
*
* @param array $vars Existing template variables.
* @return array
*/
add_filter( 'tasty_recipes_recipe_template_vars', function( $vars ) {
// If there's no image HTML already for the recipe card...
if ( empty( $vars['recipe_image'] ) ) {
$post_id = get_the_ID();
if ( $post_id ) {
$vars['recipe_image'] = get_the_post_thumbnail( $post_id, 'thumbnail' );
}
}
return $vars;
});
Save the file and test the behavior.