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.
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 http://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!
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 🙂
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.