Changeset 3715169 for simple-seo/trunk/src/link-previews.php
- Timestamp:
- 09/27/2026 08:41:32 AM (5 weeks ago)
- File:
-
- 1 edited
-
simple-seo/trunk/src/link-previews.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-seo/trunk/src/link-previews.php
r3714305 r3715169 43 43 } 44 44 45 $title = get_bloginfo( 'name' ); 46 $url = home_url( '/' ); 47 $image = null; 45 $title = get_bloginfo( 'name' ); 46 $description = current_description(); 47 $url = home_url( '/' ); 48 $image = null; 48 49 49 50 if ( $post_id ) { … … 52 53 $url = (string) get_permalink( $post_id ); 53 54 $image = featured_image( $post_id ); 55 56 // No meta description: the excerpt, if someone wrote one. Not an automatic excerpt from the 57 // content, which is usually a worse summary than the apps' own. 58 if ( '' === $description ) { 59 $description = trim( (string) preg_replace( '/\s+/', ' ', wp_strip_all_tags( (string) get_post_field( 'post_excerpt', $post_id ) ) ) ); 60 } 54 61 } 55 62 … … 72 79 'og:site_name' => get_bloginfo( 'name' ), 73 80 'og:title' => $title, 74 'og:description' => current_description(),81 'og:description' => $description, 75 82 'og:url' => $url, 76 83 'og:image' => $image['url'] ?? '', … … 79 86 'og:image:alt' => $image['alt'] ?? '', 80 87 // Apps that read twitter:card take everything else from the og: tags. 81 'twitter:card' => $image ? 'summary_large_image' : 'summary',88 'twitter:card' => $image && is_wide( $image ) ? 'summary_large_image' : 'summary', 82 89 ]; 83 90 … … 106 113 107 114 /** 115 * Whether an image suits a large, wide preview card: at least 600 px wide and wider than tall. 116 * A small or square image, like a site icon, gets the small card instead of being cropped or blurred. 117 * An image without a known size (from the filter) counts as wide. 118 * 119 * @param array{url: string, width?: int, height?: int} $image The image. 120 */ 121 function is_wide( array $image ): bool { 122 $width = (int) ( $image['width'] ?? 0 ); 123 $height = (int) ( $image['height'] ?? 0 ); 124 125 return ! $width || ( $width >= 600 && $width > $height ); 126 } 127 128 /** 108 129 * The post's featured image at full size, or null. 109 130 *
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)