I want to display a default featured image if there hasn't been one set. I googled for a solution and all I could find was this piece of code (below). My question is, is there a way of displaying a default image by writing a function inside the functions.php? I don't want to repeat myself with the code.
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
<?php } ?>