WordPress.org

Ready to get started?Download WordPress

Forums

Twitter Cards
[resolved] Add filters (4 posts)

  1. Modern Tribe, Inc.
    Member
    Posted 2 years ago #

    Thanks for putting this project together!

    I'd like this plugin to work on !is_single() pages and I'd like to set some defaults for the data. In order to do this, I've modified the plugin to include some filters. I've posted a diff here: https://gist.github.com/3044321

    I'd be delighted if you'd include this in your next release!

    Thanks!

    http://wordpress.org/extend/plugins/twitter-cards/

  2. Modern Tribe, Inc.
    Member
    Posted 2 years ago #

    With the updates in my patch, here's how I integrated the plugin in our site so that our logo shows up on non single pages and so that our twitter account is linked in:

    // Twitter cards
    
    // Display cards on every page instead of only single.
    function tribe_twitter_cards_display() {
    	return true;
    }
    add_filter( 'twitter_cards_display', 'tribe_twitter_cards_display' );
    
    // Filter twitter URL. (not really using this... it can be deleted)
    function tribe_twitter_cards_url( $url ) {
    	return $url;
    }
    add_filter( 'twitter_cards_url', 'tribe_twitter_cards_url' );
    
    // Filter twitter title.
    function tribe_twitter_cards_title( $title ) {
    	if ( !is_single() && !is_tax() ) {
    		// If this is not singel and not a category, use the blog title.
    		$title = get_bloginfo('name', 'display');
    	}
    	return $title;
    }
    add_filter( 'twitter_cards_title', 'tribe_twitter_cards_title' );
    
    // Filter twitter description.
    function tribe_twitter_cards_description( $description ) {
    	if ( !is_single() ) {
    		// if this is not single, use the site description
    		$description = get_bloginfo('description', 'display');
    	}
    	return $description;
    }
    add_filter( 'twitter_cards_description', 'tribe_twitter_cards_description' );
    
    // Filter twitter thumbnail.
    function tribe_twitter_cards_thumbnail( $thumb ) {
    	if ( !is_single() || empty($thumb) ) {
    		// If this is not single and doesn't have a thumb, then use a hardcoded logo.
    		$thumb = array(
    			'url' => get_bloginfo ( 'template_directory' ) . '/images/branding/facebook.png',
    			'width' => 114,
    			'height' => 114
    		);
    	}
    	return $thumb;
    }
    add_filter( 'twitter_cards_thumbnail', 'tribe_twitter_cards_thumbnail' );
    
    // Filter twitter account.
    function tribe_twitter_cards_site( $site ) {
    	return '@moderntribeinc';
    }
    add_filter( 'twitter_cards_site', 'tribe_twitter_cards_site' );
  3. Niall Kennedy
    Member
    Plugin Author

    Posted 1 year ago #

    You can tap into the twitter_cards_properties filter to change one or more properties before output.

  4. Niall Kennedy
    Member
    Plugin Author

    Posted 1 year ago #

    marking as resolved.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic