Make WordPress Core

Opened 16 months ago

Last modified 2 months ago

#59270 new enhancement

Excerpts Not Showing Bold Text ...

Reported by: hmnvtn's profile hmnvtn Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 6.3
Component: Editor Keywords: has-patch
Focuses: Cc:

Description

The text itself shows, but it does not show the bold attributes as it did up until 6.2.2.

Change History (25)

#1 @khokansardar
16 months ago

@hmnvtn yes, I have also checked, the issue is coming due to this line of code which actually filter excerpt based on excerpt length attributes applied in excerpt block.

<?php
$excerpt = wp_trim_words( $excerpt, $excerpt_length );

#2 @sabernhardt
16 months ago

  • Component changed from General to Editor
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 6.3.2
  • Version set to 6.3

Thanks for the report!

The tag removal in the Post Excerpt blocks was already mentioned in a comment on the pull request GB44964. However, I did not find a follow-up issue (or pull request) on the Gutenberg repository to fix it. If you would like, you could create a new issue there.

This ticket was mentioned in Slack in #core-editor by bph. View the logs.


15 months ago

#5 @frzsombor
15 months ago

Coming from similar: #59348

It looks like the "block_type_metadata" filter gives us ability to modify original Gutenberg block settings, and this way it is possible to completely remove the "excerptLength" key from the metadata attributes array. This way we can bypass wp_trim_words() and only get the untrimmed excerpt with HTML content.

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' );
Last edited 15 months ago by frzsombor (previous) (diff)

This ticket was mentioned in Slack in #core-editor by fabiankaegy. View the logs.


15 months ago

This ticket was mentioned in Slack in #core by joemcgill. View the logs.


14 months ago

This ticket was mentioned in Slack in #core by isabelbrison. View the logs.


14 months ago

#9 @audrasjb
14 months ago

  • Milestone changed from 6.3.2 to 6.4

As we're getting close to the 6.3.2 release candidate, let's move this ticket to the next release.

#10 @nicolefurlan
14 months ago

Per this comment in Slack it looks like this is still being reproduced in the latest Gutenberg trunk, so this will need a patch.

#11 @nicolefurlan
14 months ago

  • Milestone changed from 6.4 to 6.5

Bumping this to 6.5 since this bug is yet to be patched.

#12 @swissspidy
10 months ago

  • Milestone changed from 6.5 to 6.6

This ticket was mentioned in Slack in #core by joemcgill. View the logs.


8 months ago

This ticket was mentioned in Slack in #core by nhrrob. View the logs.


6 months ago

#15 @nhrrob
6 months ago

  • Milestone changed from 6.6 to 6.7

It has no movement in the last few months (and releases).
Moving to the next milestone (then future release if still doesn't receive any movement).

Still requires patch.

This ticket was mentioned in PR #6798 on WordPress/wordpress-develop by @up1512001.


6 months ago
#16

  • Keywords has-patch added; needs-patch removed

Trac ticket:
https://core.trac.wordpress.org/ticket/59270
---

As wp_trim_words function strips all HTML tags this won't allow doing any formatting to excerpt. I have used wp_kses() here with specific allowed HTML tags.

### Allowed tag list

$allowed_tags = array(
                'a'      => array(
                        'class' => array(),
                        'style' => array(),
                        'href'  => array(),
                        'id'    => array(),
                ),
                'strong' => array(),
                'b'      => array(),
                'em'     => array(),
                'img'    => array(
                        'class'  => array(),
                        'style'  => array(),
                        'src'    => array(),
                        'alt'    => array(),
                        'width'  => array(),
                        'height' => array(),
                ),
                'mark'   => array(
                        'class' => array(),
                        'style' => array(),
                ),
                'code'   => array(
                        'class' => array(),
                        'style' => array(),
                ),
                'kbd'    => array(
                        'class' => array(),
                        'style' => array(),
                ),
                'bdo'    => array(
                        'class' => array(),
                        'style' => array(),
                        'dir'   => array(),
                        'lang'  => array(),

                ),
                'span'   => array(
                        'class' => array(),
                        'style' => array(),
                ),
                'sup'    => array(
                        'class' => array(),
                        'style' => array(),
                ),
                'sub'    => array(
                        'class' => array(),
                        'style' => array(),
                ),
                's'      => array(
                        'class' => array(),
                        'style' => array(),
                ),
        );

### Example output

https://github.com/WordPress/wordpress-develop/assets/75293077/da21500c-1176-4ae9-86d0-d6d636a499b3

@up1512001 commented on PR #6798:


6 months ago
#17

Hi @swissspidy can you please review this PR?

@audrasjb commented on PR #6798:


6 months ago
#18

Hi, thanks for the PR!

I think we should consider passing $allowed_tags as an argument of wp_trim_words() so we can 1) make it optional (and maybe disabled by default? 2) allow extenders to customize it their way.

What do you think?

@up1512001 commented on PR #6798:


6 months ago
#19

@audrasjb we can definitely do that.

This ticket was mentioned in Slack in #core by up1512001. View the logs.


6 months ago

@up1512001 commented on PR #6798:


6 months ago
#21

@mukeshpanchal27 @audrasjb any update for this PR?

@up1512001 commented on PR #6798:


5 months ago
#22

@swissspidy can you please review this PR?

@swissspidy commented on PR #6798:


5 months ago
#23

Why me specifically? 😅 I am on vacation

@up1512001 commented on PR #6798:


5 months ago
#24

@swissspidy Sorry for disturbing you.

#25 @peterwilsoncc
2 months ago

  • Milestone changed from 6.7 to Future Release
  • Type changed from defect (bug) to enhancement

I've posted some notes on the associated pull request.

I think this is an enhancement to the function wp_trim_words() rather than a bug, so I've changed the ticket type and removed it from the WordPress 6.7 milestone as it's now in a bug fix phase.

Note: See TracTickets for help on using tickets.