Simply copying and pasting from google docs into wordpress adds tons of this:
<span style="font-weight: 400px">
throughout the wordpress post/page.
Found that the issue is TinyMCE. Here is a solution that prevents the spans from being added on paste: https://bionicteaching.com/clean-google-doc-cut-paste-into-wordpress-editor/
Add this to functions.php:
//fix cut paste drama from https://jonathannicol.com/blog/2015/02/19/clean-pasted-text-in-wordpress/
add_filter('tiny_mce_before_init','configure_tinymce');
/**
* Customize TinyMCE's configuration
*
* @param array
* @return array
*/
function configure_tinymce($in) {
$in['paste_preprocess'] = "function(plugin, args){
// Strip all HTML tags except those we have whitelisted
var whitelist = 'p,b,strong,i,em,h2,h3,h4,h5,h6,ul,li,ol,a,href';
var stripped = jQuery('<div>' + args.content + '</div>');
var els = stripped.find('*').not(whitelist);
for (var i = els.length - 1; i >= 0; i--) {
var e = els[i];
jQuery(e).replaceWith(e.innerHTML);
}
// Strip all class and id attributes
stripped.find('*').removeAttr('id').removeAttr('class').removeAttr('style');
// Return the clean HTML
args.content = stripped.html();
}";
return $in;
}```
-
Welcome. Why use a full length script when there are so many other much simpler alternatives?. Furthermore the script is restrictive in the sense that you can NOT just go back and forth. Once placed it will prevent you from ever changing the behaviour (unless deleted). – marikamitsos Jan 23 '20 at 17:13
You can avoid such behaviour in many different ways.
Solution 1:
You can use the Paste as text
option
Solution 2:
Instead of using the Visual editor
switch to the Text editor
.
Solution 3:
A third alternative would be to use the Clear formatting
option after pasting your text.