1

I would like to change jetpack default blank.jpg atribute on og:image. I readed some artcile in this subject, but not realy helped me. Here some trys:

/**
 * Override the default OpenGraph tags
 */
add_filter( 'jetpack_open_graph_tags', function( $tags ) {
    $tags['twitter:site'] = '@ourhandle';
    $tags['twitter:creator'] = '@ourhandle';
    $tags['og:site_name'] = 'Our Site Name';


// the og:image key defaults to the featured image. if the value is
// not set, define it as an array. if the value is set, assume it is
// the featured image (or has been previously filtered)
if ( ! isset( $tags['og:image'] ) ) {
    $tags['og:image'] = array();
}
$tags['og:image'] = (array)$tags['og:image'];

if ( is_a_particular_blog() ) {
    $blog = custom_get_blog();
    $tags['og:image'][] = custom_the_term_image_src( $blog->term_taxonomy_id );
} else {
    foreach ( get_coauthors() as $coauthor ) {
        $tags['og:image'][] = custom_get_coauthor_avatar_uri( $coauthor->ID, true );
    }
}
$tags['og:image'][] = 'http://static.oursite.org/images/oursite_opengraph_360x185.png';
return $tags;
} );



function fix_jp_og_bugs ($og_tags)
{
    $og_tags['twitter:site'] = '@laszlop';

    if  (0 == strcmp ($og_tags['og:image'],
        "https://s0.wp.com/i/blank.jpg")
    {
        unset ($og_tags['og:image']);
    }

    return $og_tags;
}

add_filter ('jetpack_open_graph_tags', 'fix_jp_og_bugs', 11);

So I would like to see this meta tag on homepage:

<meta property="og:image" content="http://www.neocsatblog.mblx.hu/wp-content/uploads/2013/04/cropped-jobbbföld-maszk-21.png" />

And not this:

<meta property="og:image" content="https://s0.wp.com/i/blank.jpg" />

I use Ifeature theme with latest wordpress and jetpack plugin.
My site is:
http://neocsatblog.mblx.hu/

3 Answers 3

1

You made that way more complicated than it needs to be.

add_filter( 'jetpack_open_graph_image_default', 'example_change_default_image' );
function example_change_default_image( $image ) {
    return 'https://s0.wp.com/i/blank.jpg';
}

Just edit the function to return whatever URL you want.

6
  • Based on your answer I add this to functions.php: add_filter( 'jetpack_open_graph_image_default', 'example_change_default_image' ); function example_change_default_image( $image ) { return 'neocsatblog.mblx.hu/wp-content/uploads/2013/04/…'; } But looks like meta tags is same, nothing happened.
    – InBug
    Sep 6, 2015 at 16:59
  • If nothing happened, then you did something incorrectly. That's the filter on the default image for the publicize function of Jetpack. It can't really get much simpler than that. So, without knowing what you're actually doing, and what you're trying to do, nobody can answer your question.
    – Otto
    Sep 7, 2015 at 0:50
  • How can can i do this wrong ? I mean i copyed and paste youre answer to functions.php
    – InBug
    Sep 7, 2015 at 5:57
  • I have no idea how you can do this wrong. The jetpack_open_graph_image_default filter is the correct one, you can see it in the functions.opengraph.php file on line 255. That's what jetpack uses as the fallback image. Unless you have something else modifying that, then that will let you adjust the default image.
    – Otto
    Sep 7, 2015 at 15:05
  • Thx the tipp, actually the direct way is worked, but the functions way not
    – InBug
    Sep 7, 2015 at 17:48
0

This is the official way to do it

Create a 200x200 image and place it in a publicly accessible URL in your site. Best way to do this is to use Wordpress' built in media uploader.

Then add to your theme’s functions.php file one of the following snippets:

A) for making the chosen image show up on the home page:

function fb_home_image( $tags ) {
    if ( is_home() || is_front_page() ) {
        // Remove the default blank image added by Jetpack
        unset( $tags['og:image'] );

        $fb_home_img = 'YOUR_IMAGE_URL';
        $tags['og:image'] = esc_url( $fb_home_img );
    }
    return $tags;
}
add_filter( 'jetpack_open_graph_tags', 'fb_home_image' );

B) for making the chosen image show up on any page that doesn't have a featured image:

function custom_jetpack_default_image() {
    return 'YOUR_IMAGE_URL';
}
add_filter( 'jetpack_open_graph_image_default', 'custom_jetpack_default_image' );
0

I'm going to agree with Otto on the proper (and super simple) way of doing this, and add to it that this is the default override for og:description ...

add_filter( 'jetpack_open_graph_fallback_description', 'change_default_description' ); function change_default_description( $data ) { return 'Put your default descriptions here'; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.