1

Simply copying and pasting from google docs into wordpress adds tons of this: <span style="font-weight: 400px"> throughout the wordpress post/page.

0

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;
}```
| improve this answer | |
  • 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 at 17:13
0

You can avoid such behaviour in many different ways.

Solution 1:
You can use the Paste as text option

enter image description here

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.