Support » Plugins » Hacks » removing wp-caption div

  • Hi there. I would like to know how can I eliminate the wp-caption div from some posts, according to an “if” statement. For example, I would like to be able to display the post pictures only for the articles posted in the last week… I used a function that filters the images for older posts, but it only clears the picture and leaves the wp-caption div unaltered. Is there a way to remove it too? 10x.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Assuming the element is empty, you could use CSS to hide it from the modern browsers (CSS selector won’t work for some older browsers).

    div.wp-caption:empty { display:none }

    ..for the sake of providing a quick fix… 🙂



    Ok, thank you for your quick answer, but how can I do this? The wp-caption div is something inside the wordpress files, automatically integrated inside the_content. How can I insert div.wp-caption:empty after a certain If statement?

    The code would go inside your theme’s stylesheet assuming the suggestion works. You of course couldn’t do a conditional statement in the stylesheet, but if the element you were referring to is indeed empty, the above CSS should work (in theory) without the need for any PHP code.



    My code is very simple:
    <div class=”entry”><?php the_content(); ?> </div>
    As I said, the wp-caption div is part of the_content function, but that div still has to be shown for some posts. I only want to eliminate the picture and the caption div around it for certain posts, so I cannot make the div empty as a general rule. Is there a way to do this?

    still no idea?

    Open a page that has a WP generated caption on it and view-source in your browser. WordPress adds the divs and classes mentioned. You don’t have to do that.

    If you have some kind of logic to determine which posts have the caption and which don’t then you can use a the_content filter to strip the caption, but you have to be able to identify the posts by some mechanism– by category, by tag, something. You could probably also use some targeted css to simply hide the caption.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘removing wp-caption div’ is closed to new replies.