Make WordPress Core

Changeset 56244


Ignore:
Timestamp:
07/17/2023 01:45:24 AM (21 months ago)
Author:
isabel_brison
Message:

Editor: trim footnote anchors from post excerpts.

Adds the excerpt_remove_footnotes function to trim footnote anchors from post excerpts.

Props: ramonopoly, costdev, mukesh27, mcsf, azaozz.
Fixes #58805.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r56183 r56244  
    10111011
    10121012/**
     1013 * Parses footnotes markup out of a content string,
     1014 * and renders those appropriate for the excerpt.
     1015 *
     1016 * @since 6.3.0
     1017 *
     1018 * @param string $content The content to parse.
     1019 * @return string The parsed and filtered content.
     1020 */
     1021function excerpt_remove_footnotes( $content ) {
     1022    if ( ! str_contains( $content, 'data-fn=' ) ) {
     1023        return $content;
     1024    }
     1025
     1026    return preg_replace(
     1027        '_<sup data-fn="[^"]+" class="[^"]+">\s*<a href="[^"]+" id="[^"]+">\d+</a>\s*</sup>_',
     1028        '',
     1029        $content
     1030    );
     1031}
     1032
     1033/**
    10131034 * Renders inner blocks from the allowed wrapper blocks
    10141035 * for generating an excerpt.
  • trunk/src/wp-includes/formatting.php

    r56191 r56244  
    39533953 * @since 1.5.0
    39543954 * @since 5.2.0 Added the `$post` parameter.
     3955 * @since 6.3.0 Removes footnotes markup from the excerpt content.
    39553956 *
    39563957 * @param string             $text Optional. The excerpt. If set to empty, an excerpt is generated.
     
    39673968        $text = strip_shortcodes( $text );
    39683969        $text = excerpt_remove_blocks( $text );
     3970        $text = excerpt_remove_footnotes( $text );
    39693971
    39703972        /*
     
    40094011        $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[&hellip;]' );
    40104012        $text         = wp_trim_words( $text, $excerpt_length, $excerpt_more );
     4013
    40114014    }
    40124015
Note: See TracChangeset for help on using the changeset viewer.