Skip to content

Instantly share code, notes, and snippets.

@hearvox
Last active May 7, 2019 01:35
Show Gist options
  • Save hearvox/b1f9778b16aec9864459 to your computer and use it in GitHub Desktop.
Save hearvox/b1f9778b16aec9864459 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' );
?>
@hearvox
Copy link
Author

hearvox commented Feb 1, 2015

Validate Facebook's Open Graph data:
https://developers.facebook.com/tools/debug/

Validate Twitter Card data:
https://cards-dev.twitter.com/validator

Jetpack info for Open Graph:
http://jetpack.me/tag/open-graph/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment