The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS WP, need different background for p and img Re: WP, need different background for p and img


@AntonNiklasson, I may be in the minority, but I respectfully disagree with you. I find a link to an actual live page/site is far better than a test bed. If a live page is not available, then I agree and think a test bed is better than just posting code (or worse an image, or still worse just trying to describe the problem).

, I’m not a wordpress guy, but I can think of three things you could try. The simplest is to use a caption on the image. I believe WP will then wrap the image in a div instead of p. The caption could be just a single space, or you could use CSS to hide the caption with .wp-caption-text {display: none}.

The second thing you could do is use jquery to add a class to p’s that have img.

$(document).ready(function() {

should work.

The third and most technical would be to edit the functions.php so that images would be wrapped in an element of your chosing.

// img unautop
function img_unautop($pee) {
$pee = preg_replace('/

\s*?(<\/a>|)?\s*<\/p>/s', '

', $pee);
return $pee;
add_filter( 'the_content', 'img_unautop', 30 );

courtesy Robert O’Rourke