0

Is there a way to add a class to all parent elements inside the_content?

My problem is I'm using this kind of css selector:

.post_content>* {margin-bottom:10px;}

This is to due with mostly paragraphs, but also any other element that might be added to the post which won't be wrapped in a paragraph.

I thought the best way to avoid this (as its an expensive selector) would be to add a class to those elements.

I would like a php solution, a filter in the_content that would let me add (not replace) the class of elements just below .post_content (or parent elements in $content).

Thank you

  • 1
    Would you mind telling us why you're trying to do that? Maybe there's a fix for the root of the problem. – kaiser Feb 11 '14 at 5:34
  • I just try to avoid the use of * selector. I want each paragraph or other element (ul,div...) (which are parent of the_content "result") to have certain css properties, for example margin-bottom. I just want to know if there is a way of avoid the use of the star selector.Thanks – Alvaro Feb 11 '14 at 11:33
  • But why do you need to space anything that far? That was my question. – kaiser Feb 11 '14 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.