WordPress可视化编辑器TinyMce如何保留自定义属性

WordPress可视化编辑器TinyMce如何保留自定义属性

本文介绍了WordPress可视化编辑器TinyMce如何保留自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个WordPress插件,该插件向WP中的tinymce编辑器添加了按钮。我正在向DOM元素(如data-initial = 3 ..)添加自定义属性,但WordPress不会保存它们。即使我尝试在切换到可视化编辑器时尝试在html编辑器中编写自定义属性,但自定义属性都不再存在时。

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.

制作WP的任何解决方案保留自定义属性吗?

Any solutions to make WP preserve custom attributes ?

谢谢!

推荐答案

您需要添加您的自定义属性到 rel =

You need to add your custom attributes to valid_elements in the tinymce init

valid_elements: "@[id|class|title|style|data-initial|...]," + //Your attributes HERE!!!
        "a[name|href|target|title]," +
        "#p,-ol,-ul,-li,br,img[src],-sub,-sup,-b,-i," +
        "-span,hr",

在编辑器中将其删除-否则tinymce清理功能将删除它们(因为它们无效)。

in order to keep them in the editor - otherwise the tinymce cleanup functionality will remove them (because they are not valid).

这篇关于WordPress可视化编辑器TinyMce如何保留自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!