I have the_excerpt() in a specific page, I need to strip a div and keep the text, but only in the excerpt of that page.

I believe I need to create a function with custom excerpt, but I don't how to do it. Tested several solutions I found here and nothing worked.

1 Answer 1


If it's just needed in one place, you could use the following:

echo wp_strip_all_tags( get_the_excerpt() );

Keep in mind, using the custom excerpt field will automatically remove all tags. Creating an excerpt automatically from the post content will not.

If you want more control, you can use wp_trim_excerpt() or wp_trim_words().

See: Using wp_trim_excerpt to get the_excerpt() outside the loop

In your case, it would look like this:

echo wp_strip_all_tags( wp_trim_words( get_the_excerpt(), 60, '[...]' ) );

wp_trim_words() allows you to pass in the text source, number of words, and the more text. You can remove the more text by setting this to false.

  • Thanks, but doesn't work. I have this. <?php if( $content_source == 'content' ) the_content(); else the_excerpt() ?>
    – PauloP
    Commented Mar 8, 2019 at 13:45
  • What happens when you use this? <?php if( $content_source == 'content' ) { the_content(); } else { echo wp_strip_all_tags( get_the_excerpt() ); } ?> Commented Mar 8, 2019 at 13:51
  • Wonderful! Works great! Is there a way to limit the number of words in that particular line?! I am asking, because it strips the div, but not the text that's inside the div.
    – PauloP
    Commented Mar 8, 2019 at 14:29
  • Updating my answer to include this. Commented Mar 8, 2019 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.