Hi there,
I’m having a very difficult time with the twitter card on my site. When I enable Yoast it does not work at all, a mere link shows up on twitter, no image.
So I added this code into the header.php file in the child theme:
<?php
#twitter cards hack
if(is_single() || is_page()) {
$twitter_url = get_permalink();
$twitter_title = get_the_title();
$twitter_desc = get_the_excerpt();
$twitter_thumbs = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full );
$twitter_thumb = $twitter_thumbs[0];
if(!$twitter_thumb) {
$twitter_thumb = 'http://catiesorganics.com/wp-content/uploads/2016/06/Caites-fb-website-image.jpg';
}
$twitter_name = str_replace('@', '', get_the_author_meta('twitter'));
?>
<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="@catiesorgancis" />
<?
if($twitter_name) {
?>
<meta name="twitter:creator" value="@<?php echo $twitter_name; ?>" />
<?
}
}
?>
The twitter card works throughout the site but not on the home page. When I add a specific image to the twitter card then it appears site wide rather than pulling the page/post specific image.
How on earth do I get this to work properly? I’m about to pull my hair out messing with this. Any help would be greatly appreciated. Thank You!
This is a wordpress site.