Forums

What's the best way to add a default image to posts? (3 posts)

  1. kondef
    Member
    Posted 1 year ago #

    Hello!

    I would like to have a default image attached to posts automatically, if no specific image is selected instead.

    I seem to recall finding a plug-in that fit this functionality, which also could associate images with certain categories. Unfortunately, I can't seem to find it now.

    Can someone suggest code or a relevant plug-in to achieve this?

    Thank you!

    K

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    <?php if( has_post_thumbnail() ) : the_post_thumbnail();
    else :?> <img src="<?php bloginfo('stylesheet_directory'); ?>/images/default.jpg" width="xx" height="yy" alt="" />
    <?php endif;?>
  3. kondef
    Member
    Posted 1 year ago #

    Hey Esmi,

    Thanks for your reply. When I add that code to my index page, I get an error message stating that the function is undefined. Any thoughts?

    Fatal error: Call to undefined function: has_post_thumbnail() in /home/content/k/o/n/kontainer/html/SALMELAND/blog/wp-content/themes/MyTheme/index.php on line 12

Topic Closed

This topic has been closed to new replies.

About this Topic