Tagged: fallback, featured image, page, post, search, search results
-
AuthorPosts
-
October 22, 2018 at 11:18 pm #1025173
Hi,
in case I forgot to upload a featured image to
– posts
– pagesI would like to show a default image, that also appears in the search results!
I found here from @ismael an old snippet:
https://kriesi.at/support/topic/change-default-thumbnail-image/#post-668404add_filter('avf_loop_index_blog_meta', 'avf_loop_index_blog_meta_mod', 10, 1); function avf_loop_index_blog_meta_mod($output) { $link = get_permalink(); $fallback = strpos($output, 'iconfont'); if ($fallback <= 200) { $output = "<a href='{$link}' class='small-preview' title='Advanced Post'><img src='FALLBACK IMAGE URL HERE'/></a>"; } return $output; }
P.S.: yes, I have replaced in the snippet the right image path :-)
but when I look at my search results, then all the posts & pages, where I forgot to upload a featured image, still have not the default featured image; maybe this snippet is is not the right one for showing a default featured image of posts & pages (!) in the search results because “iconfont” appears in the snippet?
Somewhere in the internet I found this snippet, but it still does not work with ENFOLD:
if ( has_post_thumbnail() ) { the_post_thumbnail(); } else { ?> <background-image=url("https://mysite.de/wp-content/uploads/sites/2/2018/10/defaultfeaturedimage.jpg")> <?php }
Could you please give me a newer, right snippet for it (no plugin)? Thanks a lot.
October 23, 2018 at 11:11 pm #1025680Hey Gitte,
How and where ahve you added that snippet? :)
Best regards,
BasilisOctober 23, 2018 at 11:15 pm #1025685this snippet comes to the functions.php
October 28, 2018 at 7:22 pm #1027295Hi,
That snippet is not doing anything at all. If you want to use that you need to edit a template, where it does load it properly.
Else you have to hook in that specific section.
For further help with that as it is outside of our Support Scope, you can hire someone to help you.Best regards,
BasilisOctober 28, 2018 at 7:49 pm #1027309What ENFOLD file do I need to use for this according to @Ismael’s suggestion?
October 31, 2018 at 3:14 am #1028343Hi,
That is for the blog or single post pages. Did you modify the loop-search.php file to display the thumbnails? Please post the content of the modified file on pastebin.com.
Best regards,
IsmaelOctober 31, 2018 at 10:46 pm #1028646I still haven’t made any changes to any file in ENFOLD.
I only tried this snippet in the my Code-Snippets-Plugin (which holds every snippet that normally goes to the function.php):add_filter('avf_loop_index_blog_meta', 'avf_loop_index_blog_meta_mod', 10, 1); function avf_loop_index_blog_meta_mod($output) { $link = get_permalink(); $fallback = strpos($output, 'iconfont'); if ($fallback <= 200) { $output = "<a href='{$link}' class='small-preview' title='Advanced Post'><img src='FALLBACK IMAGE URL HERE'/></a>"; } return $output; }
But probably that is not the right snippet or it is not complete, so that also at the search results page this default fallback image appears.
November 5, 2018 at 7:15 am #1029783Hi,
Again, that snippet is for the single post pages. It’s not going to work on the search results page. Did you add any modifications the search page templates? The posts thumbnails should not be displayed on the search results page by default.
Best regards,
IsmaelNovember 5, 2018 at 10:42 am #1029822okay, thank you, I guess I understand now … but what can I do so that this default/fallback featured image is also shown in the search results. I haven’t added anything to search files of ENFOLD (and I don’t know what and how)
November 6, 2018 at 11:58 am #1030349Hi,
This thread should help you display thumbnails on the search results page:
// https://kriesi.at/support/topic/show-featured-images-in-search-results-page/
If you want to add a placeholder, look for this line:
$searchthumb = get_the_post_thumbnail( $the_id, 'large' );
Replace it with:
$placeholder = "<img src='PLACE HOLDER IMAGE HERE' />"; $searchthumb = get_the_post_thumbnail( $the_id, 'large' ); $searchthumb = $searchthumb ? $searchthumb : $placeholder;
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.