Support » Fixing WordPress » Editor removes javascript in Visual mode

  • I discovered today that WP editor strips out all javascript code if you switch to Visual mode. Of you go back to Text mode, the javascript code is gone. It does that on my two WP sites, one using the standard editor and the other using WP Editor plugin.

    Is this a known problem?

Viewing 3 replies - 1 through 3 (of 3 total)
  • It’s complicated – see https://core.trac.wordpress.org/ticket/27858.

    Thread Starter mwrmwr

    (@mwrmwr)

    I read that thread but am left with not knowing or understanding what the current status is re javascript. Is there a way (plugin?) that prevents the removal of javascript in the editor?

    What are the supposed security risks? I have admin status.

    So the flipping between visual and text edit modes in the editor causing the JavaScript to get removed is a bug of sorts (meaning it’s not intended behavior). But inserting JavaScript into the editor (and thus the content) can be a security issue as well (malicious JS code is not unheard of). So the WordPress core developers have, for now, not fixed the problem and instead encourage users who need JavaScript to be inserted into their content, to use a plugin or shortcodes to provide that capability.

    In other words, WordPress core developers won’t be fixing this, instead you will need to use something like https://gist.github.com/adamsilverstein/7741b38133fe3a593382 in your functions.php file or use a plugin that provides similar functionality to work around the “bug” that won’t be fixed because there’s better/safer ways of handling it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Editor removes javascript in Visual mode’ is closed to new replies.