• Resolved Gojero

    (@gojero)


    I was thinking of running the flex slider automatically. Changing it in the main theme is no problem at all. But it is a real pain to find out using javascript in child sketch theme. I search many forums and tried many things. Only I get is a broke website… Does anyone knows a solution for Sketch?
    And, Is it even possible to override js for Sketch?

    This is what I added latest in the child function.php. but it does not work at all…

    function my_scripts() {
        wp_dequeue_script('sketch');
        wp_enqueue_script('my_script', get_template_directory_uri() . '/js/sketch.js', array('jquery'));
    }
    
    add_action('wp_enqueue_scripts', 'my_scripts', 11);
    }

    Thank you for ideas!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Kathryn Presner

    (@zoonini)

    Hi Gojero – my colleague Frank helped out with this one – could you try this instead?

    function my_scripts() {
        wp_dequeue_script( 'sketch-script' );
    	wp_enqueue_script( 'sketch-child', get_stylesheet_directory_uri() . '/js/sketch.js', array( 'jquery', 'sketch-flexslider' ), '20140530', true );
    }
    add_action( 'wp_enqueue_scripts', 'my_scripts' );

    This adds a dependency on the Flexslider script and also targets the version number of the script that’s being enqueued. If you update the parent theme down the road you’ll need to change this part at that time: 20140530 – you’ll find it in the parent’s functions.php where the sketch.js script gets enqueued.

    Let me know how it goes.

    Moderator Kathryn Presner

    (@zoonini)

    Another difference between our snippet and yours is that the handlers need to match in the dequeueing line as well, so it needs to be sketch-script instead of just sketch, which is how it’s referenced in the parent here:

    wp_enqueue_script( 'sketch-script', get_template_directory_uri() . '/js/sketch.js', array( 'jquery' ), '20140530', true );

    Thread Starter Gojero

    (@gojero)

    Hi Kathryn,

    It goes…very good, it works.
    Thank you. And your colleague Frank! This was really helpful!
    I think more people may want to use this.
    I was very close to the solution and I see what I did wrong. I hope I can use this next time if I need to. For PHP and JS scripting I am an ‘dyslexian’.

    Because I have written one blog yet before publishing my website https://www.jeroengotz.nl
    I was thinking of doing this, because the slider is only visible when two posts are published:

    function my_scripts() {	
    
    	if ( sketch_has_featured_posts ( 1 ) ) {
        wp_dequeue_script( 'sketch-script' );
    	wp_enqueue_script( 'sketch-child', get_stylesheet_directory_uri() . '/js/my_sketch.js', array( 'jquery', 'sketch-flexslider' ), '20140530', true );
    }
    }
    add_action( 'wp_enqueue_scripts', 'my_scripts' );

    Simply changing ‘2’ in to ‘1’ did not the job. So I need to do the same thing I guess?
    Ok, It is more easy to write another post! But I was wondering how to do this.

    And thank your Frank for me! Very nice!

    Moderator Kathryn Presner

    (@zoonini)

    Glad that did the trick!

    I’m not sure I quite understand why you want to enqueue the Flexslider script if you only have one featured post, since the slider requires at least featured two posts/pages/tags to work, otherwise, there’s nothing for it to rotate to. Does that make sense?

    Thread Starter Gojero

    (@gojero)

    That makes sense. I need to write content. And…care about things that are really important ??

    Moderator Kathryn Presner

    (@zoonini)

    Yes, content is certainly important. ?? Good luck with your site.

    I’ve marked this thread as resolved but you just can start a new one if you need help with something else.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘make the flex slider run automatic’ is closed to new replies.