Skip to content

Instantly share code, notes, and snippets.

@willnorris
Created January 25, 2014 05:30
Show Gist options
  • Save willnorris/8612258 to your computer and use it in GitHub Desktop.
Save willnorris/8612258 to your computer and use it in GitHub Desktop.
<?php
function twitter_metadata($metadata) {
$metadata['twitter:card'] = 'summary';
$metadata['twitter:creator'] = '@willnorris';
foreach (array('url', 'title', 'description', 'image') as $attr) {
if (array_key_exists("og:$attr", $metadata)) {
$metadata["twitter:$attr"] = $metadata["og:$attr"];
}
}
// only return first image for twitter
if ( array_key_exists('twitter:image', $metadata) && is_array($metadata['twitter:image']) ) {
$metadata['twitter:image'] = $metadata['twitter:image'][0];
}
return $metadata;
}
add_filter('opengraph_metadata', 'twitter_metadata');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment