Search code examples
phpcodeignitertwittershare-buttontwitter-share

Twitter share link not working


I want my tweeter share button to work like the tweets actually work showing image, title and description. I have given Twitter Cards but it's not working and I don't understand why. My G+ is working perfectly and I am having some issues with Twitter and Facebook share.

My anchor tag for Twitter share is below

<a class="fa fa-twitter" href="https://twitter.com/intent/tweet?status=<?php echo base_url(); ?>index.php/Testimonials/fb_share/<?php echo $row->client_id; ?>" target="_blank"><i class="icomoon-icon-twitter"></i><span class="share-title"></span></a>

I also tried with url in place of status but still no luck

 <a class="fa fa-twitter" href="https://twitter.com/intent/tweet?url=<?php echo base_url(); ?>index.php/Testimonials/fb_share/<?php echo $row->client_id; ?>" target="_blank"><i class="icomoon-icon-twitter"></i><span class="share-title"></span></a>

My Twitter cards are below

  <!-- Twitter Card data -->
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="http://quanutrition.com/Dotcom/new/">
<meta name="twitter:title" content="<?php echo $res['name'];?>">
<meta name="twitter:description" content="<?php echo $res['content1'];?>">
<meta name="twitter:creator" content="@author_handle">
<meta name="twitter:image" content="http://quanutrition.com/Dotcom/new//admin/assets/uploads/clients_image/<?php echo $res['image'];?>">
<!-- Twitter summary card with large image must be at least 280x150px -->
<meta name="twitter:image:src" content="http://quanutrition.com/Dotcom/new//admin/assets/uploads/clients_image/<?php echo $res['image'];?>">

The $res variable looks something like this for a particular client_id

Array ( [client_id] => 1 [name] => Shikhar Dhawan [image] => shikhar-dhawan-759.jpg [video] => [content1] => "Nutrition plays a key role in my recovery and performance. Using Sports Gene testing and advance nutritional blood biochemistry helps me. Eating with a plan gets more scientific and result oriented this way."

Now I am not understanding why the Twitter cards are not working. I did G+ in the exact same manner and it worked perfectly. Can anybody suggest how to solve this?


Solution

  • First of all, you must ensure that your meta tags are available in the final static output for the URL you are sharing.

    In the case of one example testimonial page http://quanutrition.com/Dotcom/new/index.php/Testimonials/fb_share/4 I see this:

    <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:site" content="http://quanutrition.com/Dotcom/new/"> <meta name="twitter:title" content="S. Danush"> <meta name="twitter:description" content=""Qua Nutrition has helped me grow physically, sports-wise in a healthy manner and explore my strength through right nutrition. I thank my vibrant coach Mr.Veerabadran, who showed me the way to Qua Nutrition and thank my Nutritionist Suhasini for her dedicated support and guidance in helping me achieve my dream. The systematic approach of dietitians and minuscule study of body elements are the strengths of QUA. Wish that every athlete gets an opportunity to visit Qua Nutrition and get the best out of them!" "> <meta name="twitter:creator" content="@author_handle"> <!-- Twitter summary card with large image must be at least 280x150px --> <meta name="twitter:image:src" content="http://quanutrition.com/Dotcom/new//admin/assets/uploads/clients_image/DanushS.jpg">

    The twitter:description tag is broken because it has a double quotation mark on either side of the value for content.

    The twitter:creator tag is generic.

    The twitter:image:src tag name should be twitter:image. This is in the cards documentation.

    Testing your links in the Twitter Card Validator results in: ERROR: Failed to fetch page due to: DnsResolutionRequestTimeout

    This is likely because either your host is blocking Twitter's IP addresses, or there is a slow DNS resolution (5+ seconds) for your domain.

    There's troubleshooting advice on Twitter's developer forums and documentation site.