WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
[resolved] Change Twitter Card type (5 posts)

  1. Ricard Torres
    Member
    Posted 1 year ago #

    Hey guys,

    Does anyone know what filter/hook thing should I add to my functions.php file to change the Twitter Card type?

    Within the plugin you can find this:

    This defaults to summary but can be filtered using the wpseo_twitter_card_type filter.

    /**
    * Display the Twitter card type.
     *
     * This defaults to summary but can be filtered using the <code>wpseo_twitter_card_type</code> filter.
     */
    public function type() {
    	echo '<meta name="twitter:card" content="' . apply_filters( 'wpseo_twitter_card_type', 'summary' ) . '"/>' . "\n";
    }

    Any idea?

    Thanks in advance.

    http://wordpress.org/extend/plugins/wordpress-seo/

  2. Ricard Torres
    Member
    Posted 1 year ago #

    Found it, here's the solution:

    add_filter( 'wpseo_twitter_card_type', 'change_card_type', 20 );
    function change_card_type(  ) {
    	return 'summary_large_image';
    }
  3. androidgalaxy
    Member
    Posted 6 months ago #

    You can easily change card type. above is suggested method but there is another method.

    Goto Plugins->Installed Plugin->WordPress SEO-> and Click on Edit option under WordPress SEO. Look for class-twitter.php under Plugin Files.

    Hit Control+F on Chrome and enter summary on Box. It will highlight all words with summary keyword. Change Summary with summary_large_image or any other card type as given in code below. Hit save and apply for selected card. This method is not recommended but it is good for programmers...and coders.

    public function type() {
    		$type = apply_filters( 'wpseo_twitter_card_type', 'summary_large_image' );
    		if( !in_array( $type, array(  'summary_large_image', 'summary', 'photo', 'gallery', 'app', 'player', 'product' ) ) )
    			$type = 'summary_large_image';
  4. Ricard Torres
    Member
    Posted 6 months ago #

    You should never edit a plugin's code! With your suggestion you can not update the plugin anymore, if you do, you lose the changes.

    Follow my snippet and paste it within your functions.php file!

    Rick

  5. martinstoetzel
    Member
    Posted 3 months ago #

    Thanks Rick, great help!

    I have seen that in the latest Yoast SEO plugin version you can choose between Standard and Standard Large Image. I wonder why the other card twitter cards are not (yet?) available from the drop-down menu

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic