I have html, css and javascript codes from the codepen, this pen . Html and css got up fine, but with js it doesn’t work

Here is the javascript code itself:

$(document).ready(function(){ $(".Modern-Slider").slick({ autoplay:true, autoplaySpeed:10000, speed:600, slidesToShow:1, slidesToScroll:1, pauseOnHover:false, dots:true, pauseOnDotsHover:true, cssEase:'linear', // fade:true, draggable:false, prevArrow:'<button class="PrevArrow"></button>', nextArrow:'<button class="NextArrow"></button>', }); }) 

If you just add it to functions.php, it gives an error:
Parse error: syntax error, unexpected '(', expecting variable (T_VARIABLE) or '$'

Maybe you know how to connect this code?

  • @pepel_xD I tried to write wp_enqueue_script and created slider.js separately with the code inside, but it did not help. So I decided to write here as the last option - Trainandbrain_ru
  • Why do you think that you need to connect this script through functions.php ? In which part of the site, on which page you plan to use it? - alenkins

1 answer 1

If the task is to execute an arbitrary text of the script specified in functions.php, then you can put a hook on the desired function and apply this technique:

 add_action('the_post','my_custom_text_script'); function my_custom_text_script() { ?> <script> jQuery(document).ready(function($) { $(".Modern-Slider").slick({ autoplay:true, autoplaySpeed:10000, speed:600, slidesToShow:1, slidesToScroll:1, pauseOnHover:false, dots:true, pauseOnDotsHover:true, cssEase:'linear', // fade:true, draggable:false, prevArrow:'<button class="PrevArrow"></button>', nextArrow:'<button class="NextArrow"></button>', }); }); </script> <?php }