Twitter Card not working on homepage


#1

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.


#2

Also, it will not show a large image no matter what I do. Only a thumbnail to the left of the text. I’d rather have the large image with the snippet underneath.

thanks again for your help!


#3

Hi there! It looks like you’re using a Summary card, and if you’d like a larger image you should change to use the Summary Large Image type instead.

I don’t know whether it would help, but we produce our own Wordpress plugin that can add cards to your site - take a look.


#4

I made the change to “summary_large_image” and still no change in how its showing up on twitter. This is very frustrating.
https://twitter.com/CatiesOrganics


#5

No image at all for the home page… How do I get twitter to populate an image for the home page and it not be site wide? I need the post specific images to appear on twitter, which is working correctly. However, how do I get a specific image to appear for the home page?


#6

I’m sorry that this is frustrating for you! This is happening because our Cards crawler has cached your previous tags - it may take around 7 days for this change to be registered. There’s more on this in our Troubleshooting page.


#7

On the home page you are missing a twitter:description tag - add that and you should be all set, for that page.


#8

Oh good! It works now whew!! I’ve just got to wait for the caching issue but I see through the validator that its working.

Thank You!!