워드프레스에 자바스립트 파일 (js) 추가하는 법.

테마의 functions.php 파일에.

function hj_method(){
 wp_enqueue_script('스크립트이름', get_stylesheet_directory_uri().'/js/파일명.js', array(),null,true);
}
 add_action('wp_enqueue_scripts', 'hj_method');

이렇게 쓰면된다. array() 부분은 의존하는 파일의 경로인데 가령 제이쿼리 플러그인을 사용하려면 플러그인 js 파일 경로를 저기 적어준다.

get_stylesheet_directory_uri().

는 현재 테마의 style.css 파일이 있는 경로를 출력해준다. 그러니까 저 경로는 내가 사용하고 있는 테마의 js폴더 안의 파일명.js 를 불러오라는 말인거다.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
모든 댓글 보기
0
생각을 나눠주시면 감사해요!x
()
x
Please enter Google Username or ID to start!
Example: clip360net or 116819034451508671546
Title
Caption
File name
Size
Alignment
Link to
  Open new windows
  Rel nofollow