EN / ZH
How to Insert onclick in WordPress Posts

When writing articles in WordPress, if you try to insert simple scripts such as

javascript:tucao() or onclick="tucao()"

WordPress’s security mechanism will automatically filter them into:

javascript:void(0) and onclick=""

Here’s the solution:

Open the formatting.php file in the wp-include directory and comment out approximately line 2321:

$safe_text = str_replace( "\n", '\n', addslashes( $safe_text ) );

Upload the modified file, refresh the backend, and save the article that wouldn’t save before.

Then restore formatting.php to its original state.