Adding a simple Javascript file with a plugin

I just want to create an alert box when a page with a post is reloaded.

<script type="text/javascript">
window.alert("alert");
</script>

And here is the php code i wrote to load the js.

function alert_js(){
   wp_enqueue_script('likeButton', plugins_url( '/alert.js', __FILE__ ));
}
add_action('the_post', 'alert_js');

I’m sure that it successfully finds the script in right place(I checked the page source.). But somehow it acts like there is no javascript included. What I’m missing there?

Read more here: Adding a simple Javascript file with a plugin

Leave a Reply

Your email address will not be published. Required fields are marked *