2014-06-20 3 views
-5

я пытаюсь добавить два файла JS на мой сайт тему:Как включить более одного JS в тему Wordpress?

  1. JS/jscripts.js
  2. JS/самозагрузки-парят-dropdown.js

код, который я использую :

function wptuts_scripts_with_jquery() 
{ 
    // Register the script like this for a plugin: 
    wp_register_script('custom-script', plugins_url('/js/custom-script.js', __FILE__), array('jquery')); 
    // or 
    // Register the script like this for a theme: 
    wp_register_script('custom-script', get_template_directory_uri() . '/js/custom-script.js', array('jquery')); 

    // For either a plugin or a theme, you can then enqueue the script: 
    wp_enqueue_script('custom-script'); 
} 
add_action('wp_enqueue_scripts', 'wptuts_scripts_with_jquery'); 

от этой функции я могу добавить только один JS-файл, как добавить 2-й файл JS. Я новичок в Wordpress и PHP. Нужна помощь!! :)

+0

Где у вас есть эти файлы js? В папке js темы? – devo

+3

Действительно? Вы только что скопировали и ввели это непосредственно из [учебника] (http://code.tutsplus.com/articles/how-to-include-javascript-and-css-in-your-wordpress-themes-and-plugins --wp-24321), который точно объясняет, как делать то, что вы просите! – Joe

ответ

0
function wptuts_scripts_with_jquery() 
{ 

    // do this for plugin js 
    wp_register_script('custom-script', plugins_url('/js/jscripts.js', __FILE__), array('jquery')); 
    wp_register_script('drop-down', plugins_url('/js/bootstrap-hover-dropdown.js', __FILE__), array('jquery')); 


    // or this for theme js 
    wp_register_script('custom-script', get_template_directory_uri() . '/js/jscripts.js', array('jquery')); 
    wp_register_script('drop-down', get_template_directory_uri() . '/js/bootstrap-hover-dropdown.js', array('jquery')); 


    wp_enqueue_script('custom-script'); 
    wp_enqueue_script('drop-down'); 
} 
add_action('wp_enqueue_scripts', 'wptuts_scripts_with_jquery'); 
Смежные вопросы