{"id":286,"date":"2013-12-15T23:54:54","date_gmt":"2013-12-15T23:54:54","guid":{"rendered":"http:\/\/www.itcrumbs.com\/?p=286"},"modified":"2019-02-07T04:39:45","modified_gmt":"2019-02-07T04:39:45","slug":"how-to-add-a-default-fallback-image-if-no-image-can-be-found-in-a-post","status":"publish","type":"post","link":"http:\/\/www.itcrumbs.com\/?p=286","title":{"rendered":"How to add a default fallback image if no image can be found in a post"},"content":{"rendered":"<p><a title=\"http:\/\/jetpack.me\/2013\/10\/15\/add-a-default-fallback-image-if-no-image\/\" href=\"http:\/\/jetpack.me\/2013\/10\/15\/add-a-default-fallback-image-if-no-image\/\">http:\/\/jetpack.me\/2013\/10\/15\/add-a-default-fallback-image-if-no-image\/<\/a><\/p>\n<p>&#160;<\/p>\n<p>When you publish a new post on your site, Jetpack crawls it and looks for images that can be used when sharing that post on Facebook, on Twitter, or if that post appears in the Top Posts and Pages widget in your sidebar.<\/p>\n<p>Jetpack starts by looking for a Featured Image. If you didn\u2019t define any, we will look for slideshows and galleries, and then for single images you may have inserted in your posts. If you\u2019ve inserted an image that is hosted on another site, we can use it too.<\/p>\n<p>However, sometimes you may not have added any image to your post. In such cases, you can add this code snippet to your theme\u2019s functions.php file, or in a functionality plugin. This way, your readers will see a default image when sharing that post on Facebook, for example:<\/p>\n<blockquote>\n<p>function jeherve_custom_image( $media, $post_id, $args ) {     <br \/>&#160;&#160;&#160; if ( empty( $media ) ) {      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; $permalink = get_permalink( $post_id );      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; $url = apply_filters( &#8216;jetpack_photon_url&#8217;, &#8216;<a href=\"http:\/\/www.ovalnews.com\/images\/ovalnews-default-social-slim1.jpg'\">http:\/\/www.ovalnews.com\/images\/ovalnews-default-social-slim1.jpg&#8217;<\/a> );      <br \/>&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return array( array(      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216;type&#8217;&#160; =&gt; &#8216;image&#8217;,      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216;from&#8217;&#160; =&gt; &#8216;custom_fallback&#8217;,      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216;src&#8217;&#160;&#160; =&gt; esc_url( $url ),      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216;href&#8217;&#160; =&gt; $permalink,      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ) );      <br \/>&#160;&#160;&#160; }      <br \/>}      <br \/>add_filter( &#8216;jetpack_images_get_images&#8217;, &#8216;jeherve_custom_image&#8217;, 10, 3 );<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/jetpack.me\/2013\/10\/15\/add-a-default-fallback-image-if-no-image\/ &#160; When you publish a new post on your site, Jetpack crawls it and looks for images that can be used when sharing that post on Facebook, on Twitter, or if that post appears in the Top Posts and Pages widget in your sidebar. Jetpack starts by looking for a Featured Image. If you [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-286","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.itcrumbs.com\/index.php?rest_route=\/wp\/v2\/posts\/286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.itcrumbs.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.itcrumbs.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.itcrumbs.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/www.itcrumbs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=286"}],"version-history":[{"count":1,"href":"http:\/\/www.itcrumbs.com\/index.php?rest_route=\/wp\/v2\/posts\/286\/revisions"}],"predecessor-version":[{"id":682,"href":"http:\/\/www.itcrumbs.com\/index.php?rest_route=\/wp\/v2\/posts\/286\/revisions\/682"}],"wp:attachment":[{"href":"http:\/\/www.itcrumbs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.itcrumbs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=286"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.itcrumbs.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}