Twitter card not working for blog posts

  • Author
    Posts
  • #72183

    Hi,

    All my blog posts have a featured image but when posting their url in Twitter the thumb is not generated. I tried some urls at and I got the following error: ERROR: No card found.

    How can I fix this? Thanks for your help!

    #72258
    Zed
    Cryout Creations mastermind

    The theme is not responsible for how social embeds work. For fine control over how this behaves use a SEO or social sharing plugin.


    If you like our creations, help us share by rating them on WordPress.org.
    Please check the available documentation and search the forums before starting a topic.
    #72265

    I have another website using another theme and I don’t have this issue (and I haven’t installed any social SEO or sharing plugin). This is not happening when tweeting youtube’s url, the thumb is automatically generated. I tried the twitter validator https://cards-dev.twitter.com/validator and I got the following error:

    INFO:  Page fetched successfully
    INFO:  5 metatags were found
    ERROR: No card found (Card error)

    It seems that the page (website) needs to include metadata to show the image: https://twittercommunity.com/t/error-no-card-found-card-error/107179

    Any help is appreciated.

    Thanks,
    Claudia

    • This reply was modified 5 years ago by claubs.
    #72277
    Zed
    Cryout Creations mastermind

    That depends on what theme you’re comparing with. WordPress.org repository themes are not allowed to include plugin-like functionality (social embed optimizations are such functionality).


    If you like our creations, help us share by rating them on WordPress.org.
    Please check the available documentation and search the forums before starting a topic.
    #72317

    I was able to fix it just adding the following code to the child theme. Just sharing the code just in case helps someone else:

    add_action('wp_head', 'add_twitter_cards');
    function add_twitter_cards() {
        if(is_single() || is_page()) {
            $tc_url    = get_permalink();
        	$tc_title  = get_the_title();
        	$tc_description   = get_the_excerpt();
        	$tc_images = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full );
        	$tc_image_thumb  = $tc_images[0];
    		if(!$tc_image_thumb) {
       		   $tc_image_thumb = 'my-url-for-page-thumbs';
      		}
        	$tc_author   = str_replace('@', '', get_the_author_meta('twitter'));
    ?>
        <meta name="twitter:card" value="summary" />
        <meta name="twitter:site" value="@my-twitter-account" />
        <meta name="twitter:title" value="<?php echo $tc_title; ?>" />
        <meta name="twitter:description" value="<?php echo $tc_description; ?>" />
        <meta name="twitter:url" value="<?php echo $tc_url; ?>" />
        <meta name="twitter:image" value="<?php echo $tc_image_thumb; ?>" />
        <?php if($tc_author) { ?>
            <meta name="twitter:creator" value="@<?php echo $tc_author; ?>" />
    	<? }
        }
    }
    ?>

    All the best,
    Claudia

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Twitter card not working for blog posts’ is closed to new replies.