Twitter Cards meta data for header.php
<?php
// TWITTER CARDS
// place in header.php in <head> tags
if(is_single() || is_page()) {
$twitter_url = get_permalink();
$twitter_title = get_the_title();
$page_object = get_page( $post->ID );
$content = strip_shortcodes($page_object->post_content);
$twitter_desc = wp_trim_words( $content, 40);
$twitter_thumbs = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full );
$twitter_thumb = $twitter_thumbs[0];
if(!$twitter_thumb) {
$twitter_thumb = '**** default user image URL ****';
}
$twitter_name = '****twitter handle****';
?>
<meta name="twitter:card" value="summary" />
<meta name="twitter:url" value="<?php echo $twitter_url; ?>" />
<meta name="twitter:title" value="<?php echo $twitter_title; ?>" />
<meta name="twitter:description" value="<?php echo $twitter_desc; ?>" />
<meta name="twitter:image" value="<?php echo $twitter_thumb; ?>" />
<meta name="twitter:site" value="@***twitter handle for website ***" />
<?
if($twitter_name) {
?>
<meta name="twitter:creator" value="@<?php echo $twitter_name; ?>" />
<?
}
}
?>