Don't use Site Icon as fallback for og:image
The snippet can be accessed without any authentication.
Authored by
Erick Hitter
/**
* Modify Jetpack's presentation of Facebook's Open Graph tags
*/
function eth_jetpack_og_tags( $tags ) {
// Site icon is a bad fallback; see https://eth.pw/a0
if ( is_string( $tags['og:image'] ) && has_site_icon() ) {
$site_icon = get_option( 'site_icon' );
if ( $site_icon ) {
add_filter( 'jetpack_photon_skip_for_url', '__return_true' );
$site_icon = wp_get_attachment_image_url( $site_icon, 'full' );
$site_icon = pathinfo( $site_icon );
$site_icon_regex = '#' . $site_icon['filename'] . '(\-([0-9]+)x([0-9]+))?\.' . $site_icon['extension'] . '#';
if ( preg_match( $site_icon_regex, $tags['og:image'] ) ) {
$tags['og:image'] = 'https://s0.wp.com/i/blank.jpg';
unset( $tags['og:image:width'] );
unset( $tags['og:image:height'] );
unset( $tags['og:image:secure_url'] );
}
remove_filter( 'jetpack_photon_skip_for_url', '__return_true' );
}
}
return $tags;
}
add_filter( 'jetpack_open_graph_tags', 'eth_jetpack_og_tags', 99 );
Please register or sign in to comment