Standard image instead of complex thumbnail

Recently I had already presented you with a snippet automatically use the first image in the article as thumbnail can. This is always a good backup in case you forget to add a featured image to your article. But there is another method, namely the one to store a default thumbnail. So instead of using the first image of your article, the following snippet always uses the same image. This can be very useful, for example if there is no need for a special thumbnail and you just want to display a default image in such cases.

Copy the following into the Functions.php of your theme:

if(has_post_thumbnail()) {
the_post_thumbnail();
} else {
echo '';
}

A default thumbnail is sometimes sufficient

The snippet above now ensures that whenever no thumbnail or featured image is assigned, the selected default,jpg is used. Of course you can change the URL in the snippet, the alt-tag, as well as the name of the graphic file, so that it works and fits for you. Especially for WordPress blogs the method with the default image can be useful, because for posts like snippets, a special thumbnail is not necessarily required. In this case you simply can't choose one and WordPress will use the default picture. But this was only an example for the practical application, how you want to use the snippet is up to you.

About Christian

My name is Christian and I am co-founder of the platform fastWP. Here in the magazine I am responsible for the more "technical" topics but I like to write about SEO, which has been my passion for over 10 years now.

Leave a Comment

Your email address will not be published. Required fields are marked *

en_GB