Archived topic
Featured Image Attachment Page
6 replies · Started by Ernst Wilhelm on December 1, 2020
It is possible to assign a featured image to an attachment page manually. So an image can be its own featured image on its own attachment image.
How can I get this with an 'automatic process'? There are several searching plugins out in the fields which allows searching for images but they show images only for a post only in case of an existing image.
Is this clear and can you help me in this?
I've tried the code snippets already provided in request https://generatepress.com/forums/topic/how-to-show-images-attachments-in-search-results/ . Not successful, no image.
Hi there,
did you try the final code that Tom provided here:
With that applied can you share a link to where i can see the issue?
Hi. Yes I did. The code is embedded in the child functions.php. The child theme is activated.
Searching for the string slider 15 attachments are found (ok). One of them is showing a featured image which I assigned manually.
https://test.r-mediabase.eu/?s=slider
Thank you, Ernst-Wilhelm
Just to confirm, are you wanting your attachments to display their attachment image as their featured image on archive pages?
Let me know :)
Hi Tom.
Are you wanting your attachments to display their attachment image as their featured image on archive pages?
So far I have not thought about archive pages, my priority is the display in search results.
Beyond that. Yes that's it. Thanks for asking.
Ernst-Wilhelm
Haven't found much in my searches for this.
One idea.. not sure it will work:
add_filter( 'post_thumbnail_html', function( $html, $post_id ) {
if ( 'attachment' === get_post_type( $post_id ) ) {
$html = wp_get_attachment_image();
}
return $html;
}, 10, 2 );
Hi. Many thanks for your support. No. It's not working. That's the only code piece, right? We can close this support topic but I am also willing to go on with another try.
Ernst-Wilhelm