I am writing a WordPress plugin that adds buttons to the tinymce editor in WP. I am adding custom attributes to DOM elements like data-initial=”3″ .. but WordPress does not save them. Even if I try to write the custom attributes in the html editor when I switch to the visual editor and back the custom attributes are not there anymore.
Any solutions to make WP preserve custom attributes ?
Thanks!
You need to add your custom attributes to valid_elements in the tinymce init
in order to keep them in the editor – otherwise the tinymce cleanup functionality will remove them (because they are not valid).
use extended_valid_elements to add your custom attribute to existing rule . using valid_elements will break current rule
this is my example