Twitter image doesn’t work

#503468
  • Resolved PlayTime
    Rank Math free

    Hello
    I have a free version of the plugin.

    But. We have an issue with the twitter image. Preview works fine in the dashboard but doesn’t work in twitter.

    I have read a lot of articles and twitter docs and founв a solution.

    /seo-by-rank-math/includes/opengraph/class-opengraph.php

    /**
    * Output the image for Twitter.
    *
    * Only used when OpenGraph is inactive or Summary Large Image card is chosen.
    */
    public function image() {
    ….
    $this->tag( ‘twitter:image’, esc_url_raw( $image_url ) );
    }
    }

    Replaced by
    /**
    * Output the image for Twitter.
    *
    * Only used when OpenGraph is inactive or Summary Large Image card is chosen.
    */
    public function image() {
    ….
    $this->tag( ‘twitter:image:src’, esc_url_raw( $image_url ) );
    }
    }

    So, replaced twitter:image meta tag to twitter:image:src

    And now all works fine.

    Do you know something about this?

    I am thinking, what to do with that. If I update the plugin, this fix will be overwritten.

    Best regards,
    Alex

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    Please try applying the following code snippet to your site to see if the twitter:image meta tag gets replaced with twitter:image:src.

    add_filter( 'rank_math/opengraph/twitter/twitter_image', 'rm_replace_twitter_image_tag' );
    $twiter_image = '';
    function rm_replace_twitter_image_tag( $image ) {
    	global $twiter_image;
    	$twiter_image = $image;
    	return '';
    }
    
    add_action( 'rank_math/opengraph/twitter', 'rm_insert_twitter_image_tag', 50 );
    function rm_insert_twitter_image_tag() {
    	global $twiter_image;
    	if ( ! empty( $twiter_image ) ) {
    		echo '<meta name="twitter:image:src" content="' . esc_url( $twiter_image ) . '" />' . "\n";
    	}
    }

    Here’s how you can add filters/hooks to your site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how it goes. Looking forward to helping you.

    Thank you.

    Hello
    It’s works!

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘Twitter image doesn’t work’ is closed to new replies.