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