Answer the question
In order to leave comments, you need to log in
How to include js file in wordpress?
Hello, what am I doing wrong and where is my mistake?
The fact is that if I write in javascript, then the code works, but if I write in jquery, then the code simply does not work.
header.php file:
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo("charset") ?>">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Тест</title>
<link rel="icon" href="img/fa.ico" type="image/x-icon">
<?php wp_head(); ?>
</head>
<body>
<header id="mainscroll" class="header">
<div class="golova">
шапка
</div>
</header>
<?php get_header() ?>
<div class="telo">
тело
</div>
<?php get_footer() ?>
<footer id="contscroll" class="contact">
<div class="foot">
подвал
</div>
</footer>
<?php wp_footer(); ?>
</body>
</html>
<?php
add_action("wp_enqueue_scripts", "test_media");
function test_media(){
wp_enqueue_style("test-main", get_stylesheet_uri());
wp_enqueue_script('jquery');
wp_enqueue_script("test-script-main", get_template_directory_uri() . '/assets/js/script.js', array('jquery'),null,true);
}
?>
jQuery(function(){
alert("НЕ РАБОТАЕТ");
}
Answer the question
In order to leave comments, you need to log in
This is all because you forgot the parenthesis at the end:
jQuery(function(){
alert("НЕ РАБОТАЕТ");
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question