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

Inconsistent handling of line breaks in excerpts #15117

Open
dtweney opened this issue Apr 22, 2019 · 11 comments
Open

Inconsistent handling of line breaks in excerpts #15117

dtweney opened this issue Apr 22, 2019 · 11 comments
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability [Feature] Document Settings Document settings experience [Type] Bug An existing feature does not function as intended

Comments

@dtweney
Copy link

dtweney commented Apr 22, 2019

Line breaks are handled differently in Gutenberg blocks vs classic blocks
When generating excerpts, Wordpress 5.x strips out the <br> tags in Gutenberg blocks, but it replaces them with a normal space (” “) in Classic blocks.

To reproduce

  1. Create a post in WordPress using the Gutenberg editor.
  2. Type some text in the first block and insert line breaks using Shift-Enter (or
    in the code editor)
  3. Save the post as a draft.
  4. Create a post with the same text using the Classic editor.
  5. Save the post as a draft.
  6. Compare the excerpts using the expanded view in the Wordpress list of all posts. This behavior can also be seen in other places where excerpts are used.

Expected behavior
Line breaks (with <br>) should always be replaced with a normal space (" ") in excerpts.

Screenshots
Compare "This is just to say 1" (classic block) with "This is just to say 2" (Gutenberg "paragraph" block).

Screen Shot 2019-04-22 at 3 43 04 PM

Desktop (please complete the following information):
n/a

Smartphone (please complete the following information):
n/a

Additional context

  • WordPress 5.1
  • Please add the version of Gutenberg you are using in the description.
  • To report a security issue, please visit the WordPress HackerOne program: https://hackerone.com/wordpress.
@gziolo gziolo added Backwards Compatibility Issues or PRs that impact backwards compatability [Type] Bug An existing feature does not function as intended [Feature] Document Settings Document settings experience labels May 23, 2019
@amwebch
Copy link

amwebch commented Mar 5, 2020

Please note that the issue does not specifically apply only to Gutenberg, but more in general to content created in any other method than the "Classic" editor, including page builders, like Elementor in my case.

Line breaks should really be handled in the same way as paragraphs in the creation of the excerpt, therefore they should be correctly replaced with a white space in order to avoid unreadable, sticked together texts in excerpts.

Are there any updates about the resolution of this bug?

@letizia66
Copy link

Hi,
I tested in my site this workaround and it seems to work:

function my_excerpt($text = '', $raw_excerpt = '') {
    add_filter( 'the_content', 'my_content', 6 );

    // get through origin filter
    $text = wp_trim_excerpt( $text );

    remove_filter( 'the_content', 'my_content', 6 );
    return $text;
}
remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
add_filter( 'get_the_excerpt', 'my_excerpt' );

function my_content($text)
{
    return str_replace( '<br>', ' ', $text );
}

I would like to know if it could break something or it can generate some unexpected side effects.

@Marc-pi
Copy link

Marc-pi commented Aug 23, 2023

ping @richtabor / @ndiego
this an old issue but annoying daily.
another quick win to stabilize the framework

@Marc-pi
Copy link

Marc-pi commented Sep 4, 2023

@paaljoachim
Copy link
Contributor

@mtias @priethor @andreiglingeanu
This issue is also impacting WooCommerce.
It would be helpful to have someone take a look at this issue.
Thanks.

@UltimateByte
Copy link

UltimateByte commented Jan 4, 2024

Confirmed in WooCommerce with TwentyTwentyFour theme, short description of products just ignores any kind of formatting, bold, titles, line jumps, etc. That makes it pretty limiting to work with. Also I couldn't find any workaround yet, awaiting for a fix. Likely, WooCommerce will fix it by integrating Gutenberg editor before the fix is released for core WP, which would be a first.

@victorhugo81
Copy link

I'm using TwentyTwentyFour theme and have the same problem with the short product description.

@CooperatusTeam
Copy link

CooperatusTeam commented Jan 26, 2024

Since all the other slightly different issues have been closed in favor of this one, and I haven't seen it included here yet, thought I'd mention that this workaround has been useful for us so far: https://core.trac.wordpress.org/ticket/59270#comment:5

Of course, it's not an ideal long-term workaround since it would in theory break the excerpt length setting in the block, once that is finally fixed, but for now it's been working well enough for our purposes.

@azsde
Copy link

azsde commented Feb 21, 2024

@CooperatusTeam I'm not sure I understand how to apply this workaround ? Could you help me out ?

@CooperatusTeam
Copy link

@azsde You can probably add the filter referenced in the workaround through using a snippets plugin, or include it in a child theme (the latter is what I did since we were using our own theme anyway).

There's more info about filters and how to use them here: https://learn.wordpress.org/tutorial/wordpress-filter-hooks/

@azsde
Copy link

azsde commented Feb 21, 2024

@CooperatusTeam alright, if I understand correctly the modification should be done directly in the php file then ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability [Feature] Document Settings Document settings experience [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

10 participants