• Resolved Mickey Kay

    (@mcguive7)


    Hi there,

    I’ve read through the forums, and am aware of the if/else logic Jetpack uses to choose a Facebook OG image. Is it possible within Jetpack to manually select a default/fallback image to use when no image is associated with a post? It sounds like right now it’s the Gravatar, but that’s not really what I want to show – I’d much rather show our logo. Any way to make that happen?

    Thanks!
    – Mickey

    http://wordpress.org/plugins/jetpack/

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    There are different ways to work around this issue:

    • You could add your logo as a Featured Image on those posts where you didn’t insert any image.
    • You could use the jetpack_images_get_images filter to add your own fallback logo when Jetpack cannot find an image to use in the post. Here is how to do it:
      function jeherve_custom_image( $media, $post_id, $args ) {
          if ( empty( $media ) ) {
              $permalink = get_permalink( $post_id );
              $url = apply_filters( 'jetpack_photon_url', 'YOUR_LOGO_IMG_URL' );
      
              return array( array(
                  'type'  => 'image',
                  'from'  => 'custom_fallback',
                  'src'   => esc_url( $url ),
                  'href'  => $permalink,
              ) );
          }
      }
      add_filter( 'jetpack_images_get_images', 'jeherve_custom_image', 10, 3 );
    Thread Starter Mickey Kay

    (@mcguive7)

    Awesome! Thanks for the help Jeremy.

    Hi, I’ve been looking for something like this for a while. When I post something short without an image, Facebook always uses my wide header graphic.

    When I add the code, all og:image tags are removed from all posts. It doesn’t matter if they have an image or not. If I remove the code, the og:image tags reappear. All other tags remain.

    I’ve retyped it in, in case it was a copy/paste issue but the problems persist. Can you point me in the right direction to debug?

    The site is: http://www.ovalnews.com

    Any advice?

    Thanks for all the work you guys do!

    Sorry, one other addition, when included, it also removes twitter image tags as well.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    @michaeltw Looking at your site, it seems you figured things out; the fallback image is displayed nicely now.

    Do not hesitate to start a new thread if you have more questions!
    http://wordpress.org/support/plugin/jetpack#postform

    Hi, I actually removed the code temporarily to get things working.

    And sorry for hijacking the thread – is it best I start an entirely new thread?

    Thanks!

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    The code still seems to be active on my end. I can see your fallback image listed at the end of the Open Graph meta tags:
    http://i.wpne.ws/SXOo

    There are two different things going on there. I’m also using the code from your fb_home_image() post. That’s creating the default image on the home page.

    I just added the jeherve_custom_image code back in and now none of the posts have any image tags. The home page still gets it’s default image.

    I wasn’t sure if there was a conflict between the two so I tested that with the same results. I’m feeling like it has to be some typo on my part. I’ve retyped it twice and tried directly pasting with the same results.

    Thanks.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    I see, I understand now.
    I’ve tried the code I pasted earlier again, and it doesn’t create any issues on my end.

    If that doesn’t work on your site, you could remove the if( is_home() ) condition from the fb_home_image() function, thus adding your fallback image on all your posts.

    Thanks, I really appreciate your help on this. I’ll just keep trying different things. Something must be causing a conflict but I have very few plugs-ins.

    Ben N

    (@bnewtoncouk)

    Hi Jeremy,

    Kudos on a brilliant plugin.

    I’m using Jetpack to manage my most popular Posts and Pages; however, rather annoyingly it seems to be pulling my author avatar in instances where the post contains no media attachment (although they do have a featured image).

    I tried to use your code snippet above, although I get:

    Warning: Illegal string offset 'src' in /home/bnewtonc/public_html/blog/wp-content/plugins/jetpack/modules/widgets/top-posts.php on line 179

    and;

    Warning: Illegal string offset 'from' in /home/bnewtonc/public_html/blog/wp-content/plugins/jetpack/modules/widgets/top-posts.php on line 180

    Do you know what might be causing this?

    Thanks in advance for your time! 🙂

    Ben.

    Forgot to add, the URL is at my blog: http://blog.bnewton.co.uk

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    however, rather annoyingly it seems to be pulling my author avatar in instances where the post contains no media attachment (although they do have a featured image).

    My code won’t help you in such situations, as the Gravatar fallback appears before the custom fallback we’ve defined here.

    The notices indicate some problems with the images used in the widget, though. That might explain why your Featured Images are not picked up by the Top Posts widgets. Could you try to reupload that Featured Image?

    If that doesn’t help, could you start your own thread and point me to a few of the posts where the Featured Image is not picked up by the widget?

    Thanks!

    I just tried the workaround for the first time in Jetpack 2.7 it was making pages with images return http://wordpress.com/i/blank.jpg

    Fixed it by changing:

    if ( empty( $media ) ) {

    to

    if ( $media ) {return $media;}
        else {

    Hi Jeremy,

    I added your code to functions.php, but it doesn’t seem to get executed at all. Even when I put some debugging code in that function to write to a file, it doesn’t get written.

    Moreover, when I put some code in class.jetpack-post-images.php, get_images function it doesn’t get executed.

    I must be missing something obvious here.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Help: can I specify a default/fallback image?’ is closed to new replies.