WordPress.org

Forums

Setting custom link image as default (5 posts)

  1. aronk
    Member
    Posted 1 year ago #

    How can I set a specific custom link image as default, so I dont need to change every time and write the url that I want.

    Thanks in advance

  2. Hardeep Asrani
    Member
    Posted 1 year ago #

    You can either use this plugin: http://wordpress.org/plugins/default-featured-image/

    Or by replacing image hook in your theme with following code:

    All you really have to do is open the theme file where you are going to display the post thumbnail, this can be (home.php, single.php, loop.php, index.php, archive.php, etc). Then simply paste the following code within the post loop.

    <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
    <?php } ?>
  3. aronk
    Member
    Posted 1 year ago #

    Thanks for the fast answer. But I oppened the index.php and inserted the function: (I want to redirect to google per example)

    <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else { ?>
    <img src="http://google.com" />
    <?php } ?>

    But is still not working. What am I doing wrong? Thanks

  4. Hardeep Asrani
    Member
    Posted 1 year ago #

    The default fallback image will only appear if the post doesn't have a featured image, otherwise the featured image will appear.

    Make sure you link to a valid image file as http://google.com is not an image file.

  5. aronk
    Member
    Posted 1 year ago #

    No. I want that my image has an link redirecting to google. I dont want to change every single time to 1-custom link 2-http://www.google.com

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.