最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

shortcode - wp_enqueue_scripts does not work on admin page

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论