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.

I've got a post format of Image, and I am running into an issue where the image is being wrapped by a <p> tag. I want to get rid of that tag (specifically on the single.php version) of those post types.

How can I get inside the formatting in a theme and remove the <p> tags, or create any format that I want for the output of this type of post, without affecting posts of a different post format?

share|improve this question
1  
Why does the <p> tag matter? My guess is that basic problem is just the styling. In that case, I imagine that a CSS solution is the easiest. –  s_ha_dum Aug 8 '13 at 22:31
    
the <p> is your friend. You should really learn how to use it. –  westondeboer Aug 9 '13 at 0:14

2 Answers 2

If this post type is called "image", you can create a single template to handle the display of just the image post type.

Just copy your 'single.php' file and rename the copy 'single-image.php'. Now you can control just the image posts. To strip out tags, I like to use the strip_tags() function. If you print the content of the post with the_content() it already applies the content filter, wrapping lines in <p> tags.

Here is an example of how you could get the content of your image without the tags:

$imageContent = get_the_content();
$stripped = strip_tags($imageContent, '<p> <a>'); //replace <p> and <a> with whatever tags you want to keep after the strip
echo $stripped;

Hope this helps!

share|improve this answer

Wordpress automatically ads the <p> tags to the content. So it shows up while loading the content. This is with the filter wpautop. So we will remove this filter for the image post type only. You can manage this by adding the following code in functions.php file.

// Add the filter to manage the p tags
add_filter( 'the_content', 'wti_remove_autop_for_image', 0 );

function wti_remove_autop_for_image( $content )
{
     global $post;

     // Check for single page and image post type and remove
     if ( is_single() && $post->post_type == 'image' )
          remove_filter('the_content', 'wpautop');

     return $content;
}

is_single() checks if a single post is being displayed.

share|improve this answer

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.