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

Wordpress 6.3 removes html tags from custom excerpt #1

Closed
lightbulbheaduk opened this issue Aug 19, 2023 · 6 comments
Closed

Wordpress 6.3 removes html tags from custom excerpt #1

lightbulbheaduk opened this issue Aug 19, 2023 · 6 comments

Comments

@lightbulbheaduk
Copy link
Owner

Upgrade from 6.2 to 6.3 removes the html tags in the output of code the replaces the excerpt

@lightbulbheaduk
Copy link
Owner Author

lightbulbheaduk commented Aug 19, 2023

OK, so it looks like WordPress/Documentation-Issue-Tracker#687 changes were merged into 6.3 to introduce excerpt length controls within UI.

The pull request WordPress/gutenberg#44964 adds logic to packages/block-library/src/post-excerpt/index.php to check if an excerpt_length exists... if it does, then it calls "wp_trim_words()" which strips all HTML tags

$excerpt = wp_trim_words( get_the_excerpt(), $excerpt_length );

Looks like we'll need to over-ride wp_trim_words...?

@lightbulbheaduk lightbulbheaduk changed the title Wordpress 6.3 removes html tags Wordpress 6.3 removes html tags from custom excerpt Aug 19, 2023
@fisher2470
Copy link

There doesn't seem to be anyway to override the HTML stripping taking place with the query loop excerpt block

@lightbulbheaduk
Copy link
Owner Author

Yep, I agree, which is why I also made a comment on the Gutenberg report to that effect. I haven't found a sensible workaround, so I believe the right thing is for it to be fixed in the main repo

@frzsombor
Copy link

frzsombor commented Sep 14, 2023

Hi! Coming from a different issue I faced with WordPress's new way of handling excerpts.

I found that the "block_type_metadata" filter gives me ability to override original Gutenberg block settings and this way I can modify the original "excerptLength" config of the excerpt block:

function fzs_filter_metadata_registration( $metadata ) {
    if ($metadata['name'] === 'core/post-excerpt') {
        $metadata['attributes']['excerptLength'] = [
            'type' => 'number',
            'default' => 999, //any number
        ];
    }
    return $metadata;
};
add_filter( 'block_type_metadata', 'fzs_filter_metadata_registration' );

Although this does not help you with your problem directly, it is possible to completely remove the "excerptLength" key from the metadata attributes array, and hopefully this will help you too by using simply get_the_excerpt() again and not trimming it with wp_trim_words:

function fzs_filter_metadata_registration( $metadata ) {
    if ($metadata['name'] === 'core/post-excerpt') {
        unset($metadata['attributes']['excerptLength']);
    }
    return $metadata;
};
add_filter( 'block_type_metadata', 'fzs_filter_metadata_registration' );

@fisher2470
Copy link

@frzsombor that fixed my specific issue as well, thank you!

@lightbulbheaduk
Copy link
Owner Author

Fixed with solution from @frzsombor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants