• itmegamaster

    (@itmegamaster)


    Как подключить JQuery и js файл связанный с ним, подключал в header.php и в functions.php ничего не получалось и к тому же у меня не загружаются картинки из таблицы стилей. Вот пример кода:
    FUNCTIONS.PHP

    <?php
    function tema_scripts_styles() {
        wp_enqueue_style( 'style', get_stylesheet_uri());
        wp_deregister_script( 'jquery' );
        wp_register_script('jquery', '//cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js', false, null);
        wp_enqueue_script('jquery');
    }
    add_action('wp_enqueue_scripts', 'tema_scripts_styles');
    ?>

    SCRIPT.JS

    $('.nav-toggle').on('click', function(){
    $('#menu').toggleClass('active');
    });

    HEAD IN HEADER.PHP

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Document</title>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
        <link rel="stylesheet" href="style.css">
        <?php wp_head(); ?>
    </head>
    • This topic was modified 6 years ago by bcworkz. Reason: code fixed
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Script.js may not be loaded in the correct order. You should enqueue it along with jQuery. In the wp_enqueue_script() call for script.js, specify array('jquery') as the dependency argument. Be sure to call this after re-registering jQuery. When you specify a dependency, you don’t really need to enqueue the dependency as well. It doesn’t hurt to do so, but it’s not required.

    When you post code in these forums, please demarcate with backticks or use the code button. Failure to do so introduces syntax errors in your code. I fixed your topic’s code for you so it displays correctly.

Viewing 1 replies (of 1 total)
  • The topic ‘Подключение библиотеки JQuery и зависящего от нее скрипта’ is closed to new replies.