Skip to content

Instantly share code, notes, and snippets.

@wecodelaravel
Forked from hearvox/WP-social-meta.php
Created May 7, 2019 01:35
Show Gist options
  • Save wecodelaravel/33dda9b396c0adf7460dad04e68663d1 to your computer and use it in GitHub Desktop.
Save wecodelaravel/33dda9b396c0adf7460dad04e68663d1 to your computer and use it in GitHub Desktop.
Change a WordPress site's homepage default social meta added by the Jetpack plugin for Facebook's Open Graph and Twitter Card tags.
<?php
function hearvox_social_meta( $tags ) {
if ( is_home() || is_front_page() ) {
// Remove the default blank tags added by Jetpack
unset( $tags['og:description'] );
unset( $tags['og:image'] );
unset( $tags['twitter:site'] );
unset( $tags['og:title'] );
unset( $tags['og:url'] );
// Add custom tags (Twitter grabs the OG image and description)
$tags['og:description'] = 'Short description of webpage.';
$tags['og:image'] = esc_url( 'http://example.com/image-dir/image-filename.jog' );
$tags['og:title'] = esc_url( 'Title of Webpage' );
$tags['og:url'] = esc_url( 'http://example.com/' );
$tags['twitter:card'] = 'summary';
$tags['twitter:site'] = '@hearvox';
$tags['twitter:title'] = 'Title of Webpage';
}
return $tags;
}
add_filter( 'jetpack_open_graph_tags', 'hearvox_social_meta' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment