Avoid WordPress TinyMCE editor to automatically filter onClick/JS code

useWordPress website, can achieve many functions.

Sometimes we need to control the effect of object click through the onClick event.

  • For example, when embedding Google Maps, in a mask, scrolling the screen will not cause Google Maps to zoom.
  • However, when using the code added by the onClick event, when WordPress switches to "Visual Editor", the code will be cleared, causing the page to become invalid, very troublesome...

Avoid automatic deletion of code by the WordPress visual editor

To completely avoid "WordPress stripping" that code, you can add the following to your functions.php file:

//避免TINYMCE编辑器自动过滤onclick、JS、注释代码
function mod_mce($initArray) {
    $initArray['verify_html'] = false;
    return $initArray;
}
add_filter('tiny_mce_before_init', 'mod_mce');

The above method is very simple, just follow the operation, you can solve the problem.

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "Avoid WordPress TinyMCE editor to automatically filter onClick/JS code", which is helpful to you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-1990.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

Your email address will not be published. Required fields * Callout

scroll to top