Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twitter cards: add new jetpack_twitter_image_default filter #8664

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add @module sharedaddy here, so our codex parser can pick the filter up?

* @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