Skip to content

Commit

Permalink
Twitter cards: add new jetpack_twitter_image_default filter (#8664)
Browse files Browse the repository at this point in the history
Matches existing `jetpack_open_graph_image_default` filter.
  • Loading branch information
snarfed authored and dereksmart committed Feb 27, 2018
1 parent fce1683 commit 3a89a3b
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion class.jetpack-twitter-cards.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,23 @@ static function twitter_cards_tags( $og_tags ) {
}

if ( ! is_singular() || ! empty( $og_tags['twitter:card'] ) ) {
/**
* Filter the default Twitter card image, used when no image can be found in a post.
*
* @module sharedaddy, publicize
*
* @since 5.9.0
*
* @param string $str Default image URL.
*/
$image = apply_filters( 'jetpack_twitter_cards_image_default', '' );
if ( ! empty( $image ) ) {
$og_tags['twitter:image'] = $image;
}

return $og_tags;
}

$the_title = get_the_title();
if ( ! $the_title ) {
$the_title = get_bloginfo( 'name' );
Expand Down Expand Up @@ -114,6 +128,14 @@ static function twitter_cards_tags( $og_tags ) {
}
}

if ( empty( $og_tags['twitter:image'] ) && empty( $og_tags['twitter:image:src'] ) ) {
/** This action is documented in class.jetpack-twitter-cards.php */
$image = apply_filters( 'jetpack_twitter_cards_image_default', '' );
if ( ! empty( $image ) ) {
$og_tags['twitter:image'] = $image;
}
}

return $og_tags;
}

Expand Down

0 comments on commit 3a89a3b

Please sign in to comment.