Fixing the Blank Image Bug in WordPress

A recent update to this site brought a nasty bug: social networks displayed a blank image next to posts not containing any image. It was a bit tedious to manually remove them (and they can’t be removed in Flipboard).

The bug was introduced when I updated the JetPack plugin from 2.5 (if memory serves) to the latest 2.7. In a rather stupid move this version puts an og:image Open Graph tag pointing to a blank image if the post doesn’t contain one. Digging around the ‘net showed that this issue was present in 2.6 and that the folks at JetPack think that it’s good this way. Well… Leaving the offending tag’s removal the only possible way to fix it.

Fortunately this is pretty simple: add the following code to the end of the theme’s functions.php file. It will remove the og:image tag when JetPack sets the default blank image.

The code snippet fixes another issue: JetPack sets the twitter:site tag to their own Twitter account – another no-no. Just don’t forget to replace my Twitter with yours :)

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

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

    return $og_tags;
}

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