0

I'm having some issues in loading a custom jquery slider into a wordpress site I'm working on: I'm not super proficient with theme development but I'm studying hard and I spent lots of days trying with no result.

I'm using the beaver builder for the graphical aspect but I'd like to insert a content slider (which in the free version is not provided). I tried to use a ready jquery content slider called anyslider.

My issue is that I'm not sure I'm loading the jquery scripts properly: thi is how I edited the functions.php file of my child theme:

<?php

add_action( 'wp_enqueue_scripts' ,'enqueue_parent_theme_style' );

function enqueue_parent_theme_style() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );

if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);

function my_jquery_enqueue() {
   wp_deregister_script('jquery');
   wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
   wp_enqueue_script('jquery');

function add_my_script() {
  wp_enqueue_script(
    'anyslider',
    get_template_directory_uri() . '/js/jquery.anyslider.js', 
    array('jquery')
  );

  wp_enqueue_script(
    'anyslider_easing',
    get_template_directory_uri() . '/js/jquery.easing.1.3.js',
    array('jquery','anyslider')                     
  );
} 

add_action( 'wp_enqueue_scripts', 'add_my_script' );  

I tried to follow every tutorial I found by the book what am i doing wrong?

EDIT

I edited the functions.php file like this: now it's working, thanks everybody

<?php

add_action( 'wp_enqueue_scripts' ,'enqueue_parent_theme_style' );

function enqueue_parent_theme_style() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}


if( !is_admin() ){
    wp_deregister_script('jquery');
    wp_register_script('jquery', ("http://code.jquery.com/jquery-latest.min.js"), false, '');
    wp_enqueue_script('jquery');
}



add_action('wp_enqueue_scripts', 'mytheme_custom_scripts');

if (wp_script_is('jquery')) echo "<h1>IT WORKS!</h1>";
  • There are some closing brackets missing and you're loading an old jquery version, but otherwise your code looks fine. Could you describe what exactly is the problem you are experiencing? – cjbj Jun 7 '16 at 11:47
  • Yes, sorry: I tried to troubleshoot it. I added an alert window script wich is working (so I'm quite sure at least a basic version of jquery is running). when i set up the html an css markup on my page and try to call it with its function the slider doesn't work at all (I'm using the following slider as a template jwilsson.github.io/AnySlider The thing I'm not sure of is if the other two scripts are loading or not. – Marco Boncompagno Jun 7 '16 at 12:25
  • Depending on how you call it alert() wil also work in plain javascript without jquery. I'd double check that. Are you sure the enqueued scripts work with the jquery version you load? You could also try wp_script_is – cjbj Jun 7 '16 at 12:33
  • you really do not need the my_jquery_enqueue function at all, where did that come from..? you should let wordpress enqueue jquery unless you have a very very specific reason and even then it's not the best idea... – majick Jun 7 '16 at 12:37
  • i found the my_jquery_enqueue here: css-tricks.com/snippets/wordpress/…. (anyways I removed it it) I also corrected the jquery version: now it's 2.2.4. Script still not running. I found and corrected the missing brackets but nothing. – Marco Boncompagno Jun 7 '16 at 13:00
0

The enqueue_parent_theme_style() and my_jquery_enqueue() functions do not have closing brackets. Does the above code run?

Otherwise the code looks okay. Are running WordPress with WP_DEBUG set to true? https://codex.wordpress.org/Debugging_in_WordPress I use the following in my wp-config.php file:

if ($_SERVER['REMOTE_ADDR'] == '123.456.789.123') {
    define('WP_DEBUG', true);
    define('WP_DEBUG_LOG', true);
    define('WP_DEBUG_DISPLAY', false);
    @ini_set('display_errors', 0);
}
else {
    define('WP_DEBUG', false);
}
  • First of all, thanks for the debugging tip: very useful. To answer to your question: The debugging log is empty (no errors). Can you explain me better the following statement? "The enqueue_parent_theme_style() and my_jquery_enqueue() functions do not have closing brackets." I'm not sure about where in the code this error occurs (Sorry I'm a newbie and I'm not so familiar yet with the syntax) – Marco Boncompagno Jun 7 '16 at 11:51
  • he is saying every { opening a function definition must be closed with } or the php syntax will fail giving you a fatal error... you are missing two. – majick Jun 7 '16 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.