How to allow html5 data attributes in tinymce editor? Tinymce removes the custom attributes specified to a tag. How can I prevent tinymce from removing it?
-
Did the answer below solve your issue? If so you should select it as correct so others don't invest time trying to answer the question and if others find your question via search they will know the answer.Michael Fromin– Michael Fromin2017-02-13 16:15:21 +00:00Commented Feb 13, 2017 at 16:15
1 Answer
You can allow these in TinyMCE by adding the extended_valid_elements option to your TinyMCE configuration. For example you could do this:
extended_valid_elements: "*[*]"
...which should allow any tag or attribute or you can be more specific about what you want to add:
extended_valid_elements: "+@[data-options]"
This should specifically add support for data-xxx attributes on any tag but would otherwise not change what TinyMCE allows.
Note: I note you have the WordPress tag on this question. It is possible that while TinyMCE would allow a tag or attribute that WordPress would remove it on save ... if you see the attribute in the "code" view but not after its saved that is likely a WordPress issue.