-1

I am trying to print the post excerpt using the following code:

<?php echo $post->post_excerpt;  ?> 

It works fantastic the only problem is that apparently I get also predefined styles and I cannot get rid of them. How can I get the raw text - is there a different function or maybe there is a php function that returns text only?

0

Using the PHP strip_tags() function should clean out the unwanted HTML elements.

<?php
echo strip_tags( $post->post_excerpt );
?>
| improve this answer | |
0

Using the WorPress wp_strip_all_tags() function you can properly strip all HTML tags including script and style.

<?php 
echo wp_strip_all_tags( $post->post_excerpt );
?>

Note:

1).wp_strip_all_tags fx properly strip all HTML tags including script and style.while strip_tags strip HTML and PHP tags from a string only.

2).pass second parameter true if you want to remove break tag <br/> also.

<?php 
   echo wp_strip_all_tags( $post->post_excerpt, true );
?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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