Thank you for the super-fast update! In the meantime, I had gone ahead and added a few changes myself.
In humansnotbots.js, I used getElementsByTagName to avoid having to insert an id attribute into the body element:
function HumansNotBots()
{
var htmlbody = document.getElementsByTagName('body')[0];
var rep = '<a href="mailto:$1@$2.$3">$1@$2.$3</a>';
var newInnerHTML = htmlbody.innerHTML.replace(/([a-zA-Z0-9._%+-]+)\sAT\s([a-zA-Z0-9.-]+)\sDOT\s([a-zA-Z]{2,4})/g, rep);
htmlbody.innerHTML = newInnerHTML;
}
In humansnotbots.php, I used wp_enqueue_script:
/* Add javascript to html head */
function add_header () {
if ( !is_admin() )
{
wp_enqueue_script( 'humansnotbots', WP_PLUGIN_URL .'/'. plugin_basename(dirname(__FILE__)) . '/humansnotbots.js', '', '1.2', false );
}
}
add_action( 'wp_print_scripts', 'add_header' );
using the tutorial here: https://weblogtoolscollection.com/archives/2010/05/06/adding-scripts-properly-to-wordpress-part-1-wp_enqueue_script/
And to call the script, I added a function that inserts js upon the wp_footer event, which then calls the function HumansNotBots if the body has loaded:
/* Add onload after body has loaded and call function */
function add_onload() {
?>
<script type="text/javascript">
my_onload_callback = HumansNotBots(); // call function
if( typeof jQuery == "function" ) {
jQuery(my_onload_callback); // document.ready
} else {
document.getElementsByTagName('body')[0].onload = my_onload_callback; // body.onload
}
</script>
<?php
}
add_action( 'wp_footer', 'add_onload' );
using a solution I found here: https://wordpress.stackexchange.com/questions/879/adding-onload-to-body/882#882
This should be a lot safer across different themes and plugins. Feel free to use this code for one of the next update ??