Support

Account

Home Forums Front-end Issues Add Class to Paragraphs in WYSIYWG Field

Solving

Add Class to Paragraphs in WYSIYWG Field

  • I have a custom field that includes a basic WYSIWYG editor. When I call this field, on the frontend, it shows paragraph tags, but I would like to be able to dynamically add a class to all of these paragraphs for styling purposes. I would even be fine with just adding a class to anything in the editor, regardless if paragraph or not. The main issue is that I can only add classes to the field itself, and I cannot add classes to what a client would write within the editor.

  • There isn’t any realistic way of adding classed to the html generated by WP. You would need to use regular expressions to parse the html to add the classes.

    The best solution to style paragraphs is to use a CSS selector that targets them based on parent element classes that already exist and not to add a class to every p tag.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.