0

I want to get the post's excerpt TEXT ONLY.

Currently, I'm using get_the_excerpt(), but it returns a string in the following format:

<p>LOREM IPSUM!&hellip; <a href="http://localhost/post/3" class="read-more">Read More</a></p>

I need to get the LOREM IPSUM (real excerpt text) only, without the wrapping <p> tags or the <a> link inside.

Is there any way to get this string, using WordPress and PHP functions?

Thank you!

2

1 Answer 1

1

You can try this one:

$string ='<p>LOREM IPSUM!&hellip; <a href="http://localhost/post/3" class="read-more">Read More</a></p>';
$string = preg_replace('/<a[^>]*(.*?)<\/a>/s', '', $string);
echo wp_strip_all_tags($string);

//return LOREM IPSUM!…

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.