0

Is there any way I can automatically add a custom class to heading tags (like h1, h2, h3, etc..,) in the content area. I know that I can manually add a class to a sub-heading from the post editor, but I want the class to be applied to all the headings in all the posts.

for instance, a normal heading will look something like this <h2>sub-heading</h2>. I want this to be changed to <h2 class="custom-class">sub-heading</h2>.

1 Answer 1

0

Yes, there are a couple of ways you can do this. One is by creating a filter in the functions.php file, like what is done here: https://stackoverflow.com/questions/10468697/how-to-add-a-class-to-a-html-element-using-filters-in-wordpress

The other would be to use Javascript/jQuery to add classes to all the headers post load. Using the php variant would be more elegant, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.