Wordpress:仅在使用窗口小部件时才将队列排入队列

pix*_*lic 4 wordpress widget

有一种方法只有在使用窗口小部件时才能将脚本排入队列(注意,如果是活动的话,但如果它存在于页面/帖子的侧边栏内)?甚至更好:只有当某个特定字符串出现在侧边栏内时,才有办法将脚本排入队列?

Kyl*_*ing 9

只需将小部件功能中的脚本或样式表排入队列即可.这是最简单,最好的方法.

    public function widget( $args, $instance ) {
        // outputs the content of the widget

        // Enqueue a script needed for
        // the Widget's output
        wp_enqueue_script( 'your_script', $path, $deps );

        // Rest of widget output goes here...
    }
Run Code Online (Sandbox Code Playgroud)