Is there any possible way to prevent <span> tags from being stripped from a Redactor field? I've tried all I can using custom Redactor and HTMLPurifier configs to no avail.

Basically what I'm trying to do long-term is replace heading tags like <h2> and <h3> with <span> and then apply the same styling as the heading tags, perhaps by applying classes to the <span>s and going from there.

Things I've tried to no avail:

  • Added "allowedTags" rule to Redactor config
  • Added "HTML.Allowed" rule to HTML Purifier config
  • Disabled HTML Purfier for field altogether
  • Added "paragraphize": false to Redactor config

The only resource I've found regarding this is this question from 3 years ago. Haven't had any luck with those suggestions either. Thanks in advance!

1 Answer 1


Not with Redactor, but...

You can do this with the Retcon (Craft CMS Plugin).

Convert all <h2> and <h3> tags to <span>.

Code example:

{{ entry.redactorField | retconChange( [ 'h2', 'h3' ], 'span' ) }}

See Recton Docs (GitHub) for more details.

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.