Не подключается файл через wp_register_script
Не подключается Javascript файл через wp_register_script в underscores
Вот так выглядит код в файле functions.php в который я добавил fontawesome и common_my
function thematika_scripts() {
wp_register_style( 'fontawesome', get_template_directory_uri() . '/libs/fontawesome/css/fontawesome.min.css');
wp_enqueue_style('fontawesome');
wp_register_script( 'common_my', get_template_directory_uri() . '/js/common.js', array('jquery'), null, true);
wp_enqueue_script('common_my');
wp_enqueue_style( 'thematika-style', get_stylesheet_uri() );
wp_enqueue_script( 'thematika-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );
wp_enqueue_script( 'thematika-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'thematika_scripts' );
Вот так выглядит код в header.php
<head> <meta charset="<?php bloginfo( 'charset' ); ?>"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Bootstrap v3.3.1 Grid Styles --> <style>много букв...</style> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous"> <link rel="profile" href="https://gmpg.org/xfn/11"> <?php wp_head(); ?> </head>
Однако при просмотре кода страницы в браузере не отображается ссылка на файл js/common.js.
Я конечно не знаток, но я вот так подключаю JS попробуй может получится
add_action('wp_footer', 'add_scripts'); if (!function_exists('add_scripts')) { function add_scripts() { if(is_admin()) return false; wp_enqueue_script('vener', get_template_directory_uri().'/js/vener.js','','',true); } }а стили отдельно
add_action('wp_print_styles', 'add_styles'); if (!function_exists('add_styles')) { function add_styles() { if(is_admin()) return false; wp_enqueue_style( 'style', get_template_directory_uri().'/style.css', '', '', '' ); } }вто ещё что заметил
wp_register_script( 'common_my', get_template_directory_uri() . '/js/common.js', array('jquery'), null, true);У тебя в конце стоит TRUE и на сколько мне известно, эта переменная $in_footer, то есть ты указываешь скрипту отображаться в футере там где у тебя <?php wp_footer(); ?>
Спасибо за помощь.
Оказывается, все нормально подключалось - это я не догадался посмотреть код в конце страницы: часть ссылок на подгружаемые файлы отображается не в начале в , а внизу под . Это меня запутало. Осталось разобраться почему так происходит...
По поводу true - совершенно точно. Я проверил. Спасибо.