<p>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.</p>

<p>First, scaffold a custom plugin using <a href="https://pluginfactory.io/" rel="nofollow">pluginfactory.io</a>. Name the plugin what you want, don't enable any components.</p>

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

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

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

CC BY-SA 3.0
2016-08-15T17:03:14.900Z
2016-08-15T17:03:14.900Z
Mats Mikkel Rummelhoff
<p>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.</p>

<p>Your custom plugin could create it's own <a href="http://www.yiiframework.com/doc/api/1.1/CHtmlPurifier" rel="nofollow">CHtmlPurifier</a> instance and configure it however you want, though.</p>

<pre><code>$purifier = new \CHtmlPurifier();
$purifier-&gt;setOptions(array(
    'Attr.AllowedFrameTargets' =&gt; array('_blank'),
    'HTML.AllowedComments' =&gt; array('pagebreak'),
    ...
));

$value = $purifier-&gt;purify($value);
</code></pre>

CC BY-SA 3.0
2016-08-15T16:47:37.103Z
2016-08-15T16:47:37.103Z
Brad Bell
<p>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)?</p>

<p>Thank you very much for your help!</p>

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

CC BY-SA 3.0
2016-08-15T16:22:38.980Z
Front end? Back end? If it' the back end, Redactor is probably getting involved as well.
RitterKnight
CC BY-SA 3.0
2016-08-15T16:42:56.113Z
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
CC BY-SA 3.0
2016-08-15T16:45:19.417Z
"Redactor is not involved, I use a custom Redactor plugin" - that doesn't make sense. :)
Brad Bell
CC BY-SA 3.0
2016-08-15T16:47:45.323Z
Means: Redactor is not part of my problem, because a custom plugin inserts the attribute which is then removed by HTML purifier ...
MISC
<richtext>
How to customize HTML Purifier?
# How to customize HTML Purifier?

(Asked by: username_0 on 2016-08-15)

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)?

**Tags:** richtext

> **Comments:**
> **username_1**: Front end? Back end? If it' the back end, Redactor is probably getting involved as well.  
> **username_0**: 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.  
> **username_2**: "Redactor is not involved, I use a custom Redactor plugin" - that doesn't make sense. :)  
> **username_0**: Means: Redactor is not part of my problem, because a custom plugin inserts the attribute which is then removed by HTML purifier ...  

---

## 2 answers

### Answer by username_3 on 2016-08-15. Score: 3 | Accepted answer

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](https://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.


---

### Answer by username_2 on 2016-08-15. Score: 3

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();
$purifier->setOptions(array(
    'Attr.AllowedFrameTargets' => array('_blank'),
    'HTML.AllowedComments' => array('pagebreak'),
    ...
));

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


---

