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


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: