admin管理员组

文章数量:1302929

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
  • You should use admin_enqueue_scripts action hook. wordpress.stackexchange/questions/67476/… – nmr Commented Feb 28, 2021 at 11:07
  • Does this answer your question? Adding scripts to admin page in my theme – cjbj Commented Feb 28, 2021 at 11:16
  • @cjbj unfortunately no, please see share.getcloudapp/NQuJpeXm – leonardeveloper Commented Feb 28, 2021 at 11:53
Add a comment  | 

1 Answer 1

Reset to default 0

Could 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.

本文标签: shortcodewpenqueuescripts does not work on admin page