Loading Javascript in WordPress Plugin

If you’re developing a WordPress plugin and wondering how to load Javascript in your plugin, below is an example I’ve found it here. There is a hook called wp_enqueue_scripts, which should be used in lieu of init for loading scripts.

<?php
add_action('wp_enqueue_scripts','ava_test_init');

function ava_test_init() {
    wp_enqueue_script( 'ava-test-js', plugins_url( '/js/ava_test_.js', __FILE__ ));
}
Share this:

Leave a comment

Your email address will not be published. Non-standard characters in the comment form are not permitted and will be removed. Required fields are marked *