WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my image.php I am using this code to grab the image caption of each image. The problem is a paragraph tag ( <p> ) is being added around it and I don't want one to be. Could somebody tell me how to strip this tag?

<?php if ( !empty($post->post_excerpt) ) the_excerpt(); ?>
share|improve this question
up vote 1 down vote accepted

strip_tags — Strip HTML and PHP tags from a string

if (!empty($post->post_excerpt)) {
  $excerpt_raw = strip_tags(get_the_excerpt()); 
  echo $excerpt_raw;
share|improve this answer

You can also use remove_filter('the_excerpt', 'wp_autop') which is how I do it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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