HTML Purifier is deleting a custom link attribute. As I understand the HTML Purifier docs, it should be possible to customize it to allow a defined attribute. Is there in Craft CMS a defined way for doing such a customizing (like the Redactor configuration)?

Thank you very much for your help!

Edit: Would probably possible in "RichTextFieldType.php" (Line 205ff)?

  • Front end? Back end? If it' the back end, Redactor is probably getting involved as well. Aug 15, 2016 at 16:22
  • As I understand, HTML Purifier is linked to the richtext field, so front end or back end should be the same. Redactor is not involved, I use a custom Redactor plugin which inserts the custom attribute.
    – MISC
    Aug 15, 2016 at 16:42
  • 1
    "Redactor is not involved, I use a custom Redactor plugin" - that doesn't make sense. :)
    – Brad Bell
    Aug 15, 2016 at 16:45
  • 1
    Means: Redactor is not part of my problem, because a custom plugin inserts the attribute which is then removed by HTML purifier ...
    – MISC
    Aug 15, 2016 at 16:47

2 Answers 2


Like Brad says above, there's no way to configure the RichTextField's HTML Purifier instance – but you could easily create a custom fieldtype that instantiates HTML Purifier w/ different options.

First, scaffold a custom plugin using pluginfactory.io. Name the plugin what you want, don't enable any components.

Second, create a file called /fieldtypes/MyPluginHandle_RichTextFieldType.php inside your custom plugin's directory (replacing MyPluginHandle with the actual handle for your plugin, of course).

Third, paste in everything from craft/app/fieldtypes/RichTextFieldType.php into your custom fieldtype; then remove everything except the prepValueFromPost() and getName() methods. Make sure you're returning something different than "Rich Text" from the latter method, and configure \CHtmlPurifier() according to your needs inside the prepValueFromPost() method.

Finally, install your plugin and convert any existing Rich Text fields to your custom fieldtype.


There's no way to configure the default Rich Text Field's use of HTMLPurifier, unfortunately, though it has been brought up before and is on our list to look at exposing to a config file post Craft 3 launch.

Your custom plugin could create it's own CHtmlPurifier instance and configure it however you want, though.

$purifier = new \CHtmlPurifier();
    'Attr.AllowedFrameTargets' => array('_blank'),
    'HTML.AllowedComments' => array('pagebreak'),

$value = $purifier->purify($value);

Your Answer

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

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