-3

My blog (Jetpack) sends out 512x512 favicon as og:image, because theme used does not support featured images and there are no images / gallery in the post itself. I'm forced to use favicons that large, because Wordpress / theme says:

The Site Icon is used as a browser and app icon for your site. Icons must be square, and at least 512 pixels wide and tall.

Is there any solution, that would allow me to block og:image tag only for favicon (i.e. if there will be any images directly in post text or if I change my theme to one, that supports featured images, I want them to be exported as og:image; I only want to block sending favicon / Site Icon through this tag).

Edit: As per Jetpack Blog I have assumed, that the quickest solution will be to ignore above text and set my favicon to i.e. 192x192, which Facebook should ignore. However, some tests with Facebook Debugger showed, that this not always works (image isn't sometimes ignored) and this will certainly not work for other kind of social sharing services. Thus, an ability to blog og:image tag for favicons / Site Icons becomes really necessary.

closed as off-topic by fuxia Jun 6 '16 at 12:51

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Right now since favicon/site-icon you are using is 512x512px , it is not ignored. – bravokeyl Jun 3 '16 at 5:39
  • @bravokeyl: You're correct. However, this is some kind of dead circle. I must have favicon 32x32 to have Facebook ignore it and in the same time I must have it 512x512, because Wordpress / my theme tells me so: "The Site Icon is used as a browser and app icon for your site. Icons must be square, and at least 512 pixels wide and tall". For this reason I was forced to re-edit this question entirely. See, if you can adapt your answer to changed question. Thank you. – trejder Jun 5 '16 at 11:29
4

Probably through Jetpack, yet I'm not sure

Looking at your site now I can say that those open graph tags are from Jetpack Plugin.


If there is no image available in the post , Jetpack adds site-icon/favicon as the default one.

We can control output of tags using filters

  • jetpack_open_graph_tags
  • jetpack_images_get_images
  • jetpack_open_graph_image_default
  • jetpack_enable_open_graph

Remove only og:image

Place the following code in functions.php of the active theme.

function wpse_228649_remove_image_tag( $tags ) {
      unset( $tags['og:image'] );
    return $tags;
}
add_filter( 'jetpack_open_graph_tags', 'wpse_228649_remove_image_tag' );

Stating from Jetpack blog

Jetpack starts by looking for a Featured Image. If you didn’t define any, we will look for slideshows and galleries, and then for any images that may be attached to the post. If we don’t find any image attached to that post, we’ll look for single images you may have inserted in the post. If you’ve inserted an image that is hosted on another site, we can use it too.

However, sometimes you may not have added any image to your post. In that case , we can set default image using the following code.

function wpse_203094_custom_image( $media, $post_id, $args ) {
    if ( $media ) {
        return $media;
    } else {
        $permalink = get_permalink( $post_id );
        $url = 'YOUR_CUSTOM_DEFAULT_IMAGE_URL' ;

        return array( array(
            'type'  => 'image',
            'from'  => 'custom_fallback',
            'src'   => esc_url( $url ),
            'href'  => $permalink,
        ) );
    }
}
add_filter( 'jetpack_images_get_images', 'wpse_203094_custom_image', 10, 3 );

Or you can use filter to change the default one.

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

Or you can disable them entirely using:

add_filter( 'jetpack_enable_open_graph', '__return_false' );

Note

As @cjbj pointed out that some plugins like Yoast SEO can override open graph tags. The above filters/code works only for Jetpack assuming that no other plugins are overriding them.

Update

Is there any solution, that would allow me to block og:image tag only for favicon

Yes there is , we can use jetpack_images_get_images filter.If we take a look at jetpack_og_get_image src we can find that it adds core site icon like this

// Third fall back, Core Site Icon. Added in WP 4.3.

if ( empty( $image ) && ( function_exists( 'has_site_icon') && has_site_icon() ) ) {
    $image['src']     = get_site_icon_url( 512 );
    $image['width']   = '512';
    $image['height']  = '512';
}

And finally defaults to blank image like this

// Finally fall back, blank image
if ( empty( $image ) ) {
    /**
     * Filter the default Open Graph Image tag, used when no Image can be found in a post.
     *
     * @since 3.0.0
     *
     * @param string $str Default Image URL.
     */
    $image['src'] = apply_filters( 'jetpack_open_graph_image_default', 'https://s0.wp.com/i/blank.jpg' );
}

So as to make Jetpack assume that it has already got an image and there is no need to use site icon, we need to set some image.This can be done using the following code.Place this in functions.php of the active theme.

function wpse_203094_no_site_icon( $media, $post_id, $args ) {
    if ( $media ) {
        return $media;
    } else {
        return array( array(
            'src'   => '' // here we are conning Jetpack, Hurray!
        ) );
    }
}
add_filter( 'jetpack_images_get_images', 'wpse_203094_no_site_icon', 10, 3 );
  • Unless you have an SEO plugin like Yoast's installed. This will override Jetpack and then add its own open graph tags to the head. – cjbj Jun 3 '16 at 9:06
  • Thanks @cjbj , you are correct but i can say from his site that OP is not using Yoast SEO :) – bravokeyl Jun 3 '16 at 9:09
  • Yes, I saw that, but I thought it would be good to note this for people with similar issues passing by at a later time. ;-) – cjbj Jun 3 '16 at 9:11
  • @cjbj Sure, i will make a note of it. – bravokeyl Jun 3 '16 at 9:12
  • @bravokeyl This is an awesome and great answer. To make it perfect, consider adding an information, where (to which file) one should put customized wpse_228649_remove_image_tag function. Plus, consider, if you can provide an answer to updated question. Thank you. – trejder Jun 5 '16 at 11:35
1

If you know the name of the function that is adding the meta tag (and it's added in it's own).

function se_remove_meta() {
 remove_action('wp_head',  'function_name');
}
add_action( 'init', 'se_remove_meta' );

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