<p>See this config setting: <a href="http://htmlpurifier.org/live/configdoc/plain.html#HTML.AllowedAttributes" rel="nofollow noreferrer">http://htmlpurifier.org/live/configdoc/plain.html#HTML.AllowedAttributes</a></p>

<p>You should be able to use it to allow data attributes.</p>

CC BY-SA 4.0
2019-09-05T09:20:55.023Z
Thanks Clark, I am aware of the settings, however when I try something like this `"HTML.AllowedAttributes": ["img.src", "img.alt", "a.href", "*.title", "*.data"]` I get an error saying `Global attribute '*' is not supported in any elements`. Even if i try to set the attr to an element, it still doesn't allow it `Attribute 'data' in element 'a' not supported`.
I have also tried adding the `HTML.AllowedElements` setting too, to make sure the tag was allowed, but that made no difference.
zizther
CC BY-SA 4.0
2019-09-05T17:00:45.970Z
Have you tried just `.data` or `data`
Clark Nelson
CC BY-SA 4.0
2021-05-20T13:29:13.037Z
Was anyone able to get this to work?
CreateSean
CC BY-SA 4.0
2021-12-27T06:15:56.067Z
@CreateSean - https://craftcms.stackexchange.com/a/38833/10878
stevecomrie
CC BY-SA 4.0
2019-10-29T15:05:11.573Z
can confirm that using either ".data" or "data" will not work.
Chad W
CC BY-SA 4.0
2019-09-04T15:39:15.067Z
2019-09-04T15:39:15.067Z
Clark Nelson
<p>Found this, which may help someone who is smarter than I am go down a path to solve this: <a href="https://stackoverflow.com/a/29317456/584599">https://stackoverflow.com/a/29317456/584599</a></p>

CC BY-SA 4.0
2019-10-29T15:11:50.810Z
2019-10-29T15:11:50.810Z
Chad W
<p>I am looking to allow <code>data</code> attr in tags with Redactor content.</p>

<p>What should I add to the Default config settings to allow this attr?</p>

<redactor>
How to allow data attr in tags in Redactor HTML Purifer
# How to allow data attr in tags in Redactor HTML Purifer

(Asked by: username_0 on 2019-09-04)

I am looking to allow `data` attr in tags with Redactor content.

What should I add to the Default config settings to allow this attr?

**Tags:** redactor

---

## 2 answers

### Answer by username_1 on 2019-09-04. Score: 1

See this config setting: <http://htmlpurifier.org/live/configdoc/plain.html#HTML.AllowedAttributes>

You should be able to use it to allow data attributes.

> **Comments:**
> **username_0**: Thanks Clark, I am aware of the settings, however when I try something like this `"HTML.AllowedAttributes": ["img.src", "img.alt", "a.href", "*.title", "*.data"]` I get an error saying `Global attribute '*' is not supported in any elements`. Even if i try to set the attr to an element, it still doesn't allow it `Attribute 'data' in element 'a' not supported`. I have also tried adding the `HTML.AllowedElements` setting too, to make sure the tag was allowed, but that made no difference.  
> **username_1**: Have you tried just `.data` or `data`  
> **username_4**: can confirm that using either ".data" or "data" will not work.  
> **username_2**: Was anyone able to get this to work?  
> **username_3**: @CreateSean - https://craftcms.stackexchange.com/a/38833/10878  

---

### Answer by username_4 on 2019-10-29. Score: 1

Found this, which may help someone who is smarter than I am go down a path to solve this: <https://stackoverflow.com/a/29317456/584599>


---

