I'm trying to create a slider shortcode with Slick Slider and for some reason it does not work in the admin page in the page builder and I'm getting this error:
I already enqueue it in my functions.php
like so:
function custom_scripts() {
wp_enqueue_style( 'slick', '//cdn.jsdelivr/npm/[email protected]/slick/slick.css');
wp_enqueue_script( 'slick', '//cdn.jsdelivr/npm/[email protected]/slick/slick.min.js',array('jquery'), '1.0', true);
}
add_action( 'admin_enqueue_scripts', 'custom_scripts' );
And added
var $ = jQuery.noConflict();
In my shortcode function but still doesn't work, though the enqueued style and script is visible on the page already.
Note: It works fine in the front end. I just wanted to show it in the admin page so my client can see it while updating the page with page builder.
I'm trying to create a slider shortcode with Slick Slider and for some reason it does not work in the admin page in the page builder and I'm getting this error:
I already enqueue it in my functions.php
like so:
function custom_scripts() {
wp_enqueue_style( 'slick', '//cdn.jsdelivr/npm/[email protected]/slick/slick.css');
wp_enqueue_script( 'slick', '//cdn.jsdelivr/npm/[email protected]/slick/slick.min.js',array('jquery'), '1.0', true);
}
add_action( 'admin_enqueue_scripts', 'custom_scripts' );
And added
var $ = jQuery.noConflict();
In my shortcode function but still doesn't work, though the enqueued style and script is visible on the page already.
Note: It works fine in the front end. I just wanted to show it in the admin page so my client can see it while updating the page with page builder.
Share Improve this question edited Feb 28, 2021 at 11:07 leonardeveloper asked Feb 28, 2021 at 10:57 leonardeveloperleonardeveloper 1151 silver badge10 bronze badges 3 |1 Answer
Reset to default 0Could your shortcode function be running or loading before Slick.js has loaded?
Simple solution might be to load slick in the header by changing the last parameter from true to false, but this isn't really the 'correct' way as it will impact performance slightly.
If your shortcode function is in a seperate file loaded by enqueueing then add slick as a dependancy.
If it's in the HTML so loaded from a PHP file, move it to a seperate JS file, enqueue it with admin_enqueue_scripts and again add Slick as a dependency.
admin_enqueue_scripts
action hook. wordpress.stackexchange/questions/67476/… – nmr Commented Feb 28, 2021 at 11:07