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.

Hey guys,
When adding an image to a page or post wordpress is automatically adding a paragraph tag as parent holding the image.

since there is no parent selector in CSS I'd love to find a solution to apply a specific classname to those paragraphs holding an actual image.

Any idea if I can use add_filter() to apply a classname to each p that holds an image?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You could use jQuery if you don't mind to rely on JavaScript for adding the class.

$(document).ready(function() {

Update: the .has() method is probably faster, see this jsperf.com test.

$(document).ready(function() {
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.