12

I am trying to share the tweet using twitter share button and using twitter cards for post image with my link and i am using :

<meta property="og:image" content="https://farm6.staticflickr.com/5510/14338202952_93595258ff_z.jpg">
<meta property="og:title" content="SOME TEXT">
<meta property="og:description"SOME DESCRIPTION">
<meta name="twitter:site" content="THIS IS CONTENT">
<meta name="twitter:card" content="photo" />
<meta name="twitter:title" content="TWITTER CONTENT">
<meta name="twitter:description" content="TWITTER DESCRIPTION">
<meta name="twitter:image" content="https://farm6.staticflickr.com/5510/14338202952_93595258ff_z.jpg">

and for share button using this:

<a class="twitter-share-button"href="https://twitter.com/intent/tweet?text=Hello%20world">Tweet</a>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

but this code only sharing text and link on twitter not with image.

can any one tell me whats wrong with my code?

Rahul Sharma
  • 406
  • 3
  • 5
  • 17

3 Answers3

11

I just solved this issue by changing the tag name:

<meta name="twitter:image:src" content="https://example.com/img/my_image.jpg">

It seems the documentation is showing twitter:image instead of twitter:image:src.

eFox
  • 685
  • 8
  • 17
4

First, try to use complete path from http or https for example: https://webpage.com/my_path_image.jpg

Check directly in the following links:

Twitter: https://cards-dev.twitter.com/validator

Facebook: https://developers.facebook.com/tools/debug/

Antonio Moreno
  • 881
  • 8
  • 9
  • 1
    Using absolute paths was the fix for me. I was using a relative path earlier that worked just fine on Discord, Telegram, LinkedIn, and most SEO checker tools. Except Twitter and Slack. Using absolute paths worked. – Jayant Bhawal Jun 13 '21 at 20:34
  • Twitter validator told me my title was invalid if present. It wasn't present, but adding it fixed this problem for me. – Michael Hinds Sep 08 '22 at 10:05
4

If you are still pulling your hair out trying to figure out why Twitter card images are not displaying for pages on your site despite having the correct dimensions and meta tags first try hosting the image on an external server i.e. a public Amazon S3 bucket.

For reasons I have yet to discover the Twitter agent / card validator would not return the image from my server (docker containers behind NGINX proxy) even though all other Twitter and OG Graph online testers returned the image correctly.

As soon as I hosted the image elsewhere the cards worked perfectly.

paj
  • 1,177
  • 16
  • 33