Changeset 3720725 for simple-seo/trunk/src/link-previews.php
- Timestamp:
- 09/30/2026 08:45:10 AM (4 weeks ago)
- File:
-
- 1 edited
-
simple-seo/trunk/src/link-previews.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-seo/trunk/src/link-previews.php
r3715169 r3720725 30 30 31 31 /** 32 * The first 30 words of a post's text, for link previews. Headings are left out, so it starts 33 * with a sentence, not "Welcome" or "Features". '' for password-protected posts. 34 * 35 * Like core's automatic excerpt, but without running the_content: that filter renders 36 * everything (page builders, embeds) and other plugins act on it. 37 * 38 * @param int $post_id Post ID. 39 */ 40 function automatic_excerpt( int $post_id ): string { 41 if ( post_password_required( $post_id ) ) { 42 return ''; 43 } 44 45 // Text blocks only, as in core's excerpt. 46 $content = excerpt_remove_blocks( (string) get_post_field( 'post_content', $post_id ) ); 47 $content = strip_shortcodes( $content ); 48 $content = (string) preg_replace( '#<h[1-6][^>]*>.*?</h[1-6]>#is', ' ', $content ); 49 $text = trim( (string) preg_replace( '/\s+/', ' ', wp_strip_all_tags( $content ) ) ); 50 51 return wp_trim_words( $text, 30 ); 52 } 53 54 /** 32 55 * Print the tags for a post, a page, the blog page or the front page. Not on archives or search. 33 56 */ … … 54 77 $image = featured_image( $post_id ); 55 78 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. 79 // No meta description: the hand-written excerpt, else the start of the content, so a 80 // shared link never shows an empty card (2026-09-30). Link previews only: the meta 81 // description stays hand-written. 58 82 if ( '' === $description ) { 59 83 $description = trim( (string) preg_replace( '/\s+/', ' ', wp_strip_all_tags( (string) get_post_field( 'post_excerpt', $post_id ) ) ) ); 84 } 85 86 // The blog page's own content is never shown (WordPress lists the posts there), so the 87 // tagline, as on a front page with the latest posts. 88 if ( '' === $description ) { 89 $description = (int) get_option( 'page_for_posts' ) === $post_id ? get_bloginfo( 'description' ) : automatic_excerpt( $post_id ); 60 90 } 61 91 }
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)