javascript - how to load js using wp_enqueue_script? -
i'm trying call js library using wp_enqueue_script
. can't figure out i'm mistaking here also, want use plugins please tell me how use plugins directory.
add_action('wp_enqueue_scripts', 'add_custom_script'); function add_custom_script(){ wp_enqueue_script( 'jquery-custom-script', get_template_directory_uri().'/js/jquery-custom-script.js' ); }
can figure out i'm mistaking here .
you can use plugin_dir_url
function.
example:
/** * include css file myplugin. */ function myplugin_scripts() { wp_register_script( 'foo-js', plugin_dir_url( __file__ ) . 'assets/foo-custom.js' ); wp_enqueue_script( 'foo-js' ); } add_action( 'wp_enqueue_scripts', 'myplugin_scripts' );
if pass __file__
argument of current php script file path
Comments
Post a Comment