Can You Manually Enter a "Featured Image" with "Custom Fields" (3 posts)

  1. trivum
    Posted 5 years ago #

    I know there is a "Featured Image" function in the editor, but I am trying to do something a little different, and it won't let me use that feature. (It's complicated, so I won't go into it here.)

    Is there a way to still use the "Featured Image" function via "Custom Fields"? ... What would be the name to call the "Featured Image" function?


  2. Michael
    Forum Moderator
    Posted 5 years ago #

    What would be the name to call the "Featured Image" function?

    there is no such a function.

    when you use a custom field for your feature image, you would need to edit index.php (and/or single.php - depending where you want to show the image) and insert something like the following, where you want the image to show:

    <?php $feature_img = get_post_meta($post->ID,'feature',true);
    if($feature_img) { ?>
    <img class="featured" src="<?php echo $feature_img; ?>" alt="" />
    <?php } ?>

    the if statement prevents an empty img tag if the custom field is empty.
    maybe with some html around, and styled in style.css.
    assuming that the $key for the custom field is 'feature' and the value is the absolute image url (including http://)

  3. trivum
    Posted 5 years ago #

    OK, thanks. I'll see if I can play with that.

Topic Closed

This topic has been closed to new replies.

About this Topic