Retrieving first image
-
Hi Ajay, I can’t seems to get the first image in post right. Please advise thanks.
-
Will need more information – website URL and which posts are you referring to in particular. Lastly, what are you expecting to see and what you’re seeing
I am getting custom post from custom field. My image return in image array so it return id when I inspect source.
A custom post shouldn’t be an issue as the plugin supports that. But, i’m not clear what do you mean custom field and the image array?
Please see my previous post as to what I would need to see
I would like to get the first image from my post however now it is getting the featured image of my post. Is there a filter or setting to get the first image from my post? Please advise Ajay. Thanks
Thanks – I understand now. The featured image is the priority vs the first image. If the plugin can’t find the featured image, then it pulls the first image.
Please see the code here: https://github.com/WebberZone/contextual-related-posts/blob/v3.0.3/includes/media.php#L118
The filter holding the thumbnail URL is: crp_thumb_url
Hi Ajay, thanks for the reply. Saw the code, does this mean I can set priority to displaying my custom image by specifying the meta name in that function and if my custom image is null then i will get the first image from post content? Please advise thank you.
Also is the one you pointed out I can apply filter to it through my functions.php or i have to change the media.php file?
I tried commenting out other options and only include get meta field name and getting first image from post. But it seems I keep getting image ID instead of URL. Please advise
Screenshots
You are correct on the meta name. If you have a meta-field in the post that contains the direct URL of the image, then you can use that one. Alternatively, you can find this in the meta box at the bottom of the edit post screen – but with the original name (not the one in your screenshot).
Also alternatively, you can put a function in your functions.php to pull an image of your choice.
This should then
add_filter( 'crp_thumb_url', 'functionname' );You can borrow lines 132-145 which pulls out the image from the post content and then tries to get the correct size thumbnail from there
https://github.com/WebberZone/contextual-related-posts/blob/v3.0.3/includes/media.php#L132-L145Hi Ajay thanks for the reply.
Here is the meta box in my edit post screen. Do I put that in the meta field settings.
Screenshot:
Thanks!
You need the full URL of the thumbnail so something like
https://sitename.com/image.png-
This reply was modified 5 years, 4 months ago by
Ajay.
Hi Ajay, so I can’t use the meta field name “article_header_image” ?
Or I need to add in functions to parse the post meta array to image url?
If article_header_image already contains the full URL of the image then you don’t need to do anything else as the plugin should pick this up. However, if it doesn’t then you’ll need to reset it back to the default setting which is
post-imageHi Ajay, is there an example of the apply filter function? can’t seems to get the function
-
This reply was modified 5 years, 4 months ago by
The topic ‘Retrieving first image’ is closed to new replies.