Themify WordPress Themes

Category

WordPress 特定のページにだけJavascriptを読み込む方法

例えば、itemsearchというスラッグの固定ページにだけ、yk_search.jsというjavascriptのファイルを読み込ませるには、functions.phpに以下を記述する。
function yk_js_enqueue() {
    if (is_page('itemsearch')) {
        wp_register_script('yk_search', get_stylesheet_directory_uri()."/yk_search.js");
        wp_enqueue_script('yk_search');
    }
}
add_action('wp_enqueue_scripts', 'yk_js_enqueue');

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>