如何在 wordpress 中更改 tinyMCE 编辑器按钮的默认标签输出?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2037506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:33:17  来源:igfitidea点击:

How to change tinyMCE editor's button's default tag output in wordpress?

wordpressxhtmltinymce

提问by Jitendra Vyas

Wordpress Tiny MCE editor and WP own editor both has button for <blockquote>. if we select any text and press this buttom then it wraps that text with <blockquote>.....</blockquote>.

Wordpress Tiny MCE 编辑器和 WP 自己的编辑器都有用于<blockquote>. 如果我们选择任何文本并按下这个按钮,那么它会用<blockquote>.....</blockquote>.

I want to change this output to this

我想将此输出更改为此

<blockquote><div class="quote_start"><div></div></div><div class="quote_end"><div></div></div>...................................</blockquote>

How can i do this manually or is there any wordpress plugin which can do the same?

我该如何手动执行此操作,或者是否有任何可以执行此操作的 wordpress 插件?

I want to change behaviour of blockquote button in bot editor TinyMCE and WP own html editor?

我想在机器人编辑器 TinyMCE 和 WP 自己的 html 编辑器中更改 blockquote 按钮的行为?

回答by Jared

I'm not sure you can use this to add that many divs but tinymce's valid elements config parameter does allow you to replace tags.

我不确定您是否可以使用它来添加那么多 div,但 tinymce 的有效元素配置参数确实允许您替换标签。

http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/valid_elements

http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/valid_elements

For instance:

例如:

tinyMCE.init({
    valid_elements : "blockquote/div[class=quote_start]"
});

Would replace all blockquote tags with a div with the quote_start class.

将用带有quote_start 类的div 替换所有blockquote 标签。

A better way might be to ignore tinymce here and write a filter for the functions.php file of your theme. http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content. Find all the instances of blockquote and replace it with the code you want.

更好的方法可能是在这里忽略 tinymce 并为主题的 functions.php 文件编写过滤器。http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content。找到 blockquote 的所有实例并将其替换为您想要的代码。

回答by tillinberlin

Maybe adding your own button could also be an option?

也许添加自己的按钮也是一种选择?

Some starting point could be this:

一些起点可能是这样的:

http://www.deliciousdays.com/tinymcebuttons/

http://www.deliciousdays.com/tinymcebuttons/

and/or this:

和/或这个:

http://wiki.moxiecode.com/index.php/TinyMCE:API/tinymce.Editor/addButton

http://wiki.moxiecode.com/index.php/TinyMCE:API/tinymce.Editor/addButton

hope it helps? Greetz, t..

希望能帮助到你?格雷茨,t..

回答by Pekka

If you want the same functionality in two different editors, you're probably better off writing (or looking for) a Wordpress filter that can replace the code. There's this onebut it doesn't seem to be able to handle regular expressions (which you would need to replace HTML tags). Maybe this one can do what you need: Text Filter Suite

如果您希望在两个不同的编辑器中使用相同的功能,您最好编写(或寻找)一个可以替换代码的 Wordpress 过滤器。有这个,但它似乎无法处理正则表达式(您需要替换 HTML 标记)。也许这个可以满足您的需求:Text Filter Suite

回答by Dave Doolin

Getting both TinyMCE and Quicktags requires mods in two places. Here's how to do the Quicktags: http://website-in-a-weekend.net/extending-wordpress/diy-wordpress-unraveling-quicktags-wordpress-plugins/

获得 TinyMCE 和 Quicktags 需要在两个地方安装 mod。下面是如何做 Quicktags:http://website-in-a-weekend.net/extending-wordpress/diy-wordpress-unraveling-quicktags-wordpress-plugins/