Using The WordPress Enqueue Hook

theme 의 function.php 에 추가하면 테마에 js, css 파일을 불러올 수 있다.

wp_enqueue_scripts – action used to load scripts on the front-end
admin_enqueue_scripts – actionused to load scripts in the WP admin

function my_theme_scripts_function() {
   wp_enqueue_script( 'myscript', get_template_directory_uri() . '/js/myscript.js');
}
add_action('wp_enqueue_scripts','my_theme_scripts_function');

get_stylesheet_directory_uri() – 자식테마 경로 (있을 경우)
get_template_directory_uri() – 부모테마 경로

참고링크 1 :: http://www.wpexplorer.com/javascript-wordpress/
참고링크 2 :: http://www.thewordcracker.com/intermediate/how-to-load-js-files-in-wordpress/

Comments +0

Leave a Comment

Your email address will not be published.
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>