1. Home
  2. Docs
  3. WordPress Basic
  4. 테마에 스크립트, 스타일 파일 추가 방법

테마에 스크립트, 스타일 파일 추가 방법

js, css 파일을 별도로 만들어서 테마에 추가하고자 할 때

wp_enqueue_scripts 훅을 이용해서 연결할 수 있음

/**
 * Add Custom CSS, JS
 */
add_action( 'wp_enqueue_scripts', 'custom_linked_style_script', 99 );
function custom_linked_style_script() {

    // custom style css
    wp_enqueue_style( 'style-custom', get_stylesheet_directory_uri().'/style-custom.css', array(), filemtime( dirname( __FILE__ ) . '/style-custom.css' ));
    wp_enqueue_style( 'style-woocommerce', get_stylesheet_directory_uri().'/style-woocommerce.css', array(), filemtime( dirname( __FILE__ ) . '/style-woocommerce.css' ));

    // custom script js :: true -> to footer / false -> to head
    wp_enqueue_script( 'js_added', get_stylesheet_directory_uri() . '/js/js-added.js', array('jquery'), filemtime( dirname( __FILE__ ) . '/js/js-added.js' ), true);	
    
}