How I fixed broken Twitter Card images generated from my WordPress posts

Why are my Twitter Card images not showing?

I looked everywhere, in the plugin, meta tags, api documents, until…

I found the one file to fix that was keeping my images from showing up in my Twitter Cards.

Twitter Card Validator

The first thing you need to know about is the Twitter Card Validator.

You have to make sure you site is white listed, mine was and that was not the problem, but it may be the first thing you should check!

All you do is put in a url from one of your WordPress blog posts to preview what your auto-generated Twitter Card will look like.

Twitter Card Validator - White Listed

Here is what my Twitter Card looked like, notice NO IMAGE!!! ARRRRGGG!!!

Twitter Card Validator - No Image

Making Sure Settings Are Correct

Using Yoast’s WordPress SEO plugin, under the social settings I made sure I checked the “Add Twitter card meta data” checkbox and saved my changes.

Yoast SEO Twitter Card

Then I doubled checked that the meta tags are actually getting rendered in the head tag…

I thought that maybe I found the problem, maybe it was the Yoast WordPress SEO plugin using a meta tag with an extra “:src” on it?

Yoast Twitter Card Meta

Note: Twitter specifically says to use “twitter:image” mentioned in their Card Type docs, took a screenshot, see below…

Twitter Card Meta

So I tested using several different posts ( Twitter caches results once fetched for 7 days )…

In the /wp-content/plugins/wordpress-seo/frontend/class-twitter.php file starting on line 383, the code below contains a function called image_output…

	 * Outputs a Twitter image tag for a given image
	 * @param string $img The source URL to the image.
	 * @param string $tag The tag to output, defaults to image:src but can be altered for use in galleries.
	 * @return bool
	//protected function image_output( $img, $tag = 'image:src' ) {
	protected function image_output( $img, $tag = 'image' ) {
		 * Filter: 'wpseo_twitter_image' - Allow changing the Twitter Card image
		 * @api string $img Image URL string
		$img = apply_filters( 'wpseo_twitter_image', $img );

		$escaped_img = esc_url( $img );

		if ( in_array( $escaped_img, $this->shown_images ) ) {
			return false;

		if ( is_string( $escaped_img ) && $escaped_img !== '' ) {
			$this->output_metatag( $tag, $escaped_img, true );
			array_push( $this->shown_images, $escaped_img );

			return true;

		return false;

Made the change, but still not getting images on my Twitter Cards…

The Fix… Damn Robots.txt !!!

The second part of the answer came when I stumbled across Twitter URL Crawling & Caching page.

Turns out I created a ROBOTS.TXT file a loooooong time ago and it blocks all crawlers from indexing just about everything except posts and pages…

That’s a problem because Twitter wants to crawl and cache the image it is going to use in the Twitter Card for 7 days…

So I had to add special rules for “Twitterbot” to allow it to access the default WordPress uploads folder where all my images exist.

The first three lines did the trick, I am able to still block all other crawlers with the rules that appear below the first three lines.

User-agent: Twitterbot
Disallow: *
Allow: /wp-content/uploads/*

User-agent: *
Disallow: /wp-admin*
Disallow: /wp-login.php
Disallow: /wp-content*
Disallow: /*/feed
Disallow: /*/trackback
Disallow: /*?
Disallow: /*.js$
Disallow: /*.inc$
Disallow: /*.css$
Disallow: /category/
Disallow: /page/
Disallow: /pages/
Disallow: /feed/
Disallow: /feed
Disallow: /tag/
Disallow: /archives/

We Have Images!!!

With the ROBOTS.TXT file update, I am now able to generate Twitter Cards that contain images!

Summary Card

Twitter Card Validator - Summary

Summary Large Image Card

Twitter Card Validator - Summary Large Image

I still left the patch to the Yoast WordPress SEO plugin in my file to follow Twitter guidelines and will fire off an email to the Yoast development team.

For the record I did test with and without the plugin patch after the ROBOTS.txt file update and Twitter Card images showed in both instances.

Hope this helps!


  • Great article, but what I’m wondering is how quick did your images appear after you’ve changed the robots.txt file?
    Because I’ve changed it about 2 hours ago and it’s still not showing any images. Do I have to wait for 7 days for twitter to recrawl my site and fetch the image?

    -- Vale

  • Hi Vale,

    When I was testing, right after I figured out the robots.txt file was the problem, I noticed that images did not show right away, so I had to test with different urls each time.

    Eventually, the Twitter crawler eventually picked up the correct image for the urls I tested and all was well. Not sure how heavy handed Twitter is with caching, especially during the holidays, I didn’t have to wait 7 days, IMO they probably state the “up to 7 days” just in case.

    Have you tested other urls? Are other URL’s on your blog showing correct Twitter cards?

    -- Cesar Serna

  • So what do you do when you get this in the Validator and it STILL doesn’t work? INFO:

    Page fetched successfully
    INFO: 27 metatags were found
    INFO: twitter:card = summary_large_image tag found
    INFO: Card loaded successfully

    -- Geoffrey Grider

  • Hey Geoffrey, I checked out what I think is your site, based on the meta tags, you are using a CDN to deliver the Twitter card image.

    Turns out the CDN is blocking Twitter bot from crawling and caching the card image.

    You might want to check with your CDN provider to see if you can change the robots.txt settings to allow Twitterbot access to cache.

    Else, you might want to not use the CDN for Twitter cards.


    -- Cesar Serna

  • Awesome man! Just got it working. Issue was the robots file!!


    -- Kia Kamgar

  • This solved a week-long headache. THANK YOU!

    -- Stephanie

  • Hi Kia and Stephanie, THANK YOU and happy I could help!


    -- Cesar Serna

  • Made my day

    -- Muhammad Ali

  • Did you have to wait any amount of time for this to start working? I’ve been running into the same issue and just added the Twitterbot allow code to my robots.txt and am still getting the same thing. It’s been driving me nuts for months.

    -- Nate Balcom

  • Hi. I’m having this issue but don’t know where to add the code above the fix it. How do I update a Robot.txt file? Sorry, totally new to coding! Thx

    -- Dawn

  • @Nate – No, didn’t have to wait long at all, once I made the change, pictures showed right away… I did have to test with a new post every time as Twitter caches data/images for up to seven days…


    -- Cesar Serna

  • @Dawn – The robots.txt file is located on your server in the root directory of your WordPress install… If editing and uploading files to your server is a bit tricky for you… A quick search on google for WordPress plugin robots.txt editor returned this ( )… I have never used that plugin, there are several that seem to do the job of both creating and enabling you to edit a robots.txt file for your site within the WordPress admin area…


    -- Cesar Serna

  • You are awesome! Thank you!!
    The fix worked!

    -- Riger99

  • I don’t understand ! I have the same problem and I modified the robots.txt file through Yoast SEO plugin to authorize Twitterbot to crawl my WordPress site but it doesn’t works… 🙁
    I’m reading all Twitter Developpers pages about this and a lot of forums where people have the same issue but Cards Validator still doesn’t show me my image…
    help :'(

    -- Pierre

  • @Pierre I took a look at your robots.txt, try putting the twitterbot rules above the “User-agent: *” rule…

    User-agent: *
    Disallow: /wp-admin/
    Allow: /wp-admin/admin-ajax.php

    User-agent: Twitterbot
    Disallow: *
    Allow: /wp-content/uploads/*


    User-agent: Twitterbot
    Disallow: *
    Allow: /wp-content/uploads/*

    User-agent: *
    Disallow: /wp-admin/
    Allow: /wp-admin/admin-ajax.php



    -- Cesar Serna

  • Hi all,

    Very useful article thank you. If you try everything listed on this page and in the comments and you’re still seeing one or two images missing, check how large they are. Twitter has a 3mb size limit for images in the twitter cards.

    -- Courtney

  • This worked for me. The image showed up instantly!

    -- PriyankaNM

  • Thank you so much. I was going round in circles with plugins and All in One SEO. Worth noting that anyone who can’t easily access the root directory and has all in one SEO pack plugin installed, there is an option to activate robots.txt and to edit it also. I did this and images are working for me now

    -- Phil

  • Hi Cesar I tried your suggestions but still my tweets didnt show any pictures. Pls have a look and advise me. TQ

    -- david

  • you are soo lucky but am trying from last 5 days but no succes in adding twitter card. when i post on twitter but no thumbnail is loading. only blank url.

    -- Julia R Fisher

  • @Julia – I just tested, even though your twitter:image url is coming from a different domain ( ) it worked just fine for me when I tested a url from your site on the twitter card validator…

    -- Cesar Serna

  • @David – take a look at your code, you have no image declared for twitter to cache, your code missing a url/path for the content property of your twitter:image tag in the header…

    <meta property=”twitter:image” content=””>

    -- Cesar Serna

  • Totally helped solve my broken twitter image! Thank you!

    -- Jacob

  • If you’re still struggling with this, try your webhost and review the ‘HotLinks’ settings. (We’re with Bluehost where HotLinks are located under cPanel/Security. From there, in the URL field, add different variations of; i.e. with/without www and both http and https. Also add in your Twitter URL in the same way. After trying all the above, this is what finally appeared to have fixed the problem for us.

    -- Colin Clapp

  • @Colin – Thanks for sharing your solution!

    -- Cesar Serna

  • I have the same problem but only with some of my posts. Some twitter cards appear nicely with the image and some don’t. And I have no idea what’s wrong

    -- David

  • Hello,

    Though your article was very useful in understanding my problem but I couldn’t fix it due to following confusions. It would be great if you could help.

    1. Where do I find the meta tag for twitter card? I tried checking my header.php in wordpress but couldn’t locate it. However, the card validator is able to fetch everything successfully. How do I fix Img:src thing? if at all it is there.

    2. You have mentioned about the output code? But where and how do I add it? or edit it? I found class:twitter.php but didn’t understand where exactly do I make a change. (Haven’t done coding of this kind before)

    3. I checked for the robot.txt file, it says that I don’t have any robot.txt file. Do I need to create one and put the given code? or is it fine without robot.txt file?

    4. Do I need to add a separate sized image especially for Twitter for each page and post? As it mentions that the image should be of 1200×663 size and less than 1 MB. Or the Yoast SEO can convert the featured image or the URL image as required?

    Sorry for so many questions. I will be very thankful if you could help.

    -- Purvi Kamaliya

  • Thank you for sharing this simple solution! To anyone trying to figure out where to edit the robots.txt file, if you are using Yoast SEO you can edit it using that plugin under –> Tools –> File Editor!

    -- Jeff Hopp

  • You’re awesome dude! Thanks for sharing your fix, it worked for me!

    -- Anas Kaadan

  • Thanks for the tips on the robot.txt file. I gave that a try, but my pictures still don’t show up on Twitter. I’m wondering if it has something to do Github which is where I’m hosting my website.

    -- Vic Hargrave

  • Thanks, it worked like a charm! You made my day 🙂

    -- Cem

  • Thanks, and just for good measure I changed the robot.txt file at the cdn also.

    -- Roger Wilson

  • Thank you very much. I’d never have been able to fix if it weren’t for your post.

    -- Alex

  • Thank you for a great article and great additional advice. But I still don’t get any images on twitter from I used to before and I don’t recall having made any significant changes.

    The card validator keeps giving me this message for all the url’s i am trying on the domain:
    INFO: Page fetched successfully
    INFO: 2 metatags were found
    ERROR: No card found (Card error)

    Any suggestings on what to do?

    All the best

    -- Finn

  • Thank You Cesar Serna!

    Your instructions were really useful and easy to understand. I have fixed my problem.

    I was checking many articles for this issue but yours really simple and proper explanation.

    kudus 🙂

    -- Giri