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.
.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