admin管理员组文章数量:1431499
TinyMCE's Paste plugin automatically turns pasted image URLs into embedded images. /docs/plugins/paste/
I need to disable this behavior since I use TinyMCE in a forum on the frontend and I don't want to allow image embedding.
TinyMCE's Paste plugin automatically turns pasted image URLs into embedded images. https://www.tiny.cloud/docs/plugins/paste/
I need to disable this behavior since I use TinyMCE in a forum on the frontend and I don't want to allow image embedding.
Share Improve this question edited Apr 19, 2019 at 21:30 Florian Walther asked Apr 19, 2019 at 21:25 Florian WaltherFlorian Walther 1591 silver badge8 bronze badges 3 |1 Answer
Reset to default 1automatically turns pasted image URLs into embedded images
Yes, but only for URLs ending with .gif
, .jpg
, .jpeg
and .png
.
And that conversion is one of the "smart paste" features in TinyMCE — another one is when you select a text and paste an absolute URL (that begins with http
or https
), the text is automatically converted to a hyperlink (clickable link).
The relevant code is below which you can find in wp-includes/js/tinymce/plugins/paste/plugin.js
which ships with WordPress — and as of writing, WordPress is still using TinyMCE version 4.9.2.
var insertContent = function (editor, html) {
if (Settings.isSmartPasteEnabled(editor) === false) {
pasteHtml(editor, html);
} else {
smartInsertContent(editor, html);
}
};
And if you look at the code, the smart paste features are being applied only if the isSmartPasteEnabled
function returns true
. The function code:
var isSmartPasteEnabled = function (editor) {
return editor.getParam('smart_paste', true);
};
So that function basically simply checks whether the editor configuration has the smart_paste
option enabled — and it is by default enabled.
Therefore, if you'd like to disable the smart paste features, just set the smart_paste
option to false
. See example below and try a demo here:
tinymce.init({
smart_paste: false,
selector: 'textarea',
plugins: 'paste'
});
Disable the smart paste features via wp_editor()
It's very easy. Just set smart_paste
to false
in the tinymce
array:
$content = '<p>Paste an image URL:</p>';
wp_editor( $content, 'editor-id', array(
'tinymce' => array(
'smart_paste' => false,
),
) );
But remember this..
Setting the smart_paste
option to false
will disable all smart paste features. If you want to disable just the image URL-to-img
-tag conversion, then I think you'd have to copy the Paste plugin and edit where necessary.
本文标签: How to disable TinyMce39s Paste plugin from turning image URLs into embedded ltimggt
版权声明:本文标题:How to disable TinyMce's Paste plugin from turning image URLs into embedded <img>? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745570494a2664017.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
.gif
,.jpg
,.jpeg
or.png
(like this image) and it is one of the "smart paste" features in TinyMCE, and you can disable it (the feature) by settingsmart_paste
to false like this. However, you should know that disabling it will also disable (as of now, two) other "smart paste" features. – Sally CJ Commented Apr 20, 2019 at 4:43