Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

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.