有一种方法只有在使用窗口小部件时才能将脚本排入队列(注意,如果是活动的话,但如果它存在于页面/帖子的侧边栏内)?甚至更好:只有当某个特定字符串出现在侧边栏内时,才有办法将脚本排入队列?
只需将小部件功能中的脚本或样式表排入队列即可.这是最简单,最好的方法.
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)
| 归档时间: |
|
| 查看次数: |
4229 次 |
| 最近记录: |