Using WordPress to build a website allows you to 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.
Hopefully, the article "Avoiding Automatic Filtering of onClick/JS Code by the WordPress TinyMCE Editor" shared on Chen Weiliang's blog ( https://www.chenweiliang.com/ ) will be helpful to you.
Feel free to share this article's link: https://www.chenweiliang.com/cwl-1990.html
