Created
January 25, 2014 05:30
-
-
Save willnorris/8612258 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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