• Resolved Guido

    (@guido07111975)


    Hi,

    I have a meta description in the head of my WP website that can contain line breaks… The native post excerpt/summary is my meta description for that post, so I’m using get_the_excerpt() to retrieve it.

    According to the codex this excerpt should not contain line breaks, all HTML tags should be stripped off.

    Before adding preg_replace to replace the line breaks I would like to know what’s happening here? Is it because it’s printed in the head perhaps?

    Guido

Viewing 3 replies - 1 through 3 (of 3 total)
  • The generated excerpt will not contain any HTML tags because the length desired might be in the middle of a tag. But manually written excerpts can contain HTML. The get_the_excerpt function returns the manual one if it exists, or generates one if it doesn’t.

    get_the_excerpt has filters on it, so you could have code that affects it.

    Thread Starter Guido

    (@guido07111975)

    Hi Joy,

    Aha, I did not know there was a difference between both but apparently there is. I thought the excerpt filter works the same for both. So I do need to strip the line breaks from the manual one.

    Something like this does the job right:

    
    $my_excerpt = wp_strip_all_tags( get_the_excerpt(), true );
    

    Thanks.

    Guido

    • This reply was modified 5 years, 11 months ago by Guido. Reason: updated reply

    I was looking for this! Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Line breaks in the excerpt’ is closed to new replies.