Plugin Directory


Ignore:
Timestamp:
09/30/2026 08:45:10 AM (4 weeks ago)
Author:
eskapism
Message:

Update to version 1.4.0 from GitHub

File:
1 edited

Legend:

Unmodified
Added
Removed
  • simple-seo/trunk/src/link-previews.php

    r3715169 r3720725  
    3030
    3131/**
     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 */
     40function 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/**
    3255 * Print the tags for a post, a page, the blog page or the front page. Not on archives or search.
    3356 */
    … …  
    5477                $image = featured_image( $post_id );
    5578
    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.
    5882                if ( '' === $description ) {
    5983                        $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 );
    6090                }
    6191        }
Note: See TracChangeset for help on using the changeset viewer.