-6

I need to be able to add a feature image to a post as a link. The link is good, it's green check. And no I cannot upload the file and insert into post. I have the link to the image I just want feature image to use it. Why I dont want to upload it, it's because my gallery is completely OUTSIDE awful WP gallery system ! and work great as this

SO the question is. If my link is : http://www.notreaventure.com/photo-0007/images/_MG_2133.jpg and I want WP to use it as feature image, can I put this link in a custom files, let's say featureimg : http://www.notreaventure.com/photo-0007/images/_MG_2133.jpg, and add a funtion that tells the WP system to get this field and get it to feature image, so nothing will be broken. I just cannot seem to find how to hack wp to get the funtion feature image to get it's image from custom field...

can you help, thanks in advance

2
  • awfull WP gallery system — why would you say that? I'm hurt ;) — If it's the output HTML that are you are referring to as "aweful", you can easily fix it. wordpress.stackexchange.com/a/43562/10691
    – its_me
    Jul 2, 2012 at 4:13
  • @AahanKrish, sorry to hurt you feeling, but i hurge to find a solution, when i upload a folder of 100-150 images and only tell the system : do a slideshow with it. I cannot find it, so i write it, and work perfectly. Upload the folder and link it to the folder name, that it, no upload, no fancy short code, nothing else. Preloading included. If you know a WordPress plugin that just do that... i will be please to used it right away. Have a look at it : notreaventure.com/photo-0007/gal.php
    – menardmam
    Jul 2, 2012 at 15:30

1 Answer 1

1

Yes, you've guessed it right. You will need to use Custom Fields in order to define the URL for the Image that you wish to use as Featured Image for the post.

Next part is to tell the Wordpress to use the Image from URL you've in Custom Field as Featured Image. Here, you can use filter called "post_thumbnail_html". The Filter is defined in "wp-includes/post-thumbnail-template.php" file under function "get_the_post_thumbnail" and also available in the latest version of Wordpress.

The definition goes like this:

return apply_filters( 'post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr );

Here is a sample use of it:

function custom_post_thumbnail($html)
{ 
    return "<img src='https://www.google.co.in/images/srpr/logo3w.png' />";
}
add_filter('post_thumbnail_html', 'custom_post_thumbnail');

Note that above code snippet is just to give you an idea of how to use this filter. You will need to add required code to get the Custom Field value and return proper IMG tag. The best thing I would suggest to do is merely parse the Image SRC part of $html and replace it with your URL. Also don't forget to check if the Custom Field is empty; in that case, just return the default $html without altering.

I hope this helps.

Cheers,

Ruturaaj.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.