admin管理员组文章数量:1431426
I want to load a special Javascript File just when the widget is loaded in the sidebar. Where do I have to put my wp_enqueue_script(...)
lines?
class controller_widget extends WP_Widget {
function controller_widget() {
$this->color = "red";
$this->dir = plugin_dir_url(__FILE__);
$widget_ops = array('classname' => 'controller_widget', 'description' => __('Benutzerfreundlicher Controller zur eingrenzung von Objekten'));
$control_ops = array('width' => 350, 'height' => 400);
$this->WP_Widget('controller_widget', __('Controller'), $widget_ops, $control_ops);
// At the moment I load the code here, but I want to proof that it is just loaded when the widget really is shown in the sidebar.
}
}
function widget( $args, $instance ) {...}
}
Thank you!
I want to load a special Javascript File just when the widget is loaded in the sidebar. Where do I have to put my wp_enqueue_script(...)
lines?
class controller_widget extends WP_Widget {
function controller_widget() {
$this->color = "red";
$this->dir = plugin_dir_url(__FILE__);
$widget_ops = array('classname' => 'controller_widget', 'description' => __('Benutzerfreundlicher Controller zur eingrenzung von Objekten'));
$control_ops = array('width' => 350, 'height' => 400);
$this->WP_Widget('controller_widget', __('Controller'), $widget_ops, $control_ops);
// At the moment I load the code here, but I want to proof that it is just loaded when the widget really is shown in the sidebar.
}
}
function widget( $args, $instance ) {...}
}
Thank you!
Share Improve this question edited Apr 24, 2019 at 9:07 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Sep 12, 2011 at 16:34 andredandred 1033 bronze badges 1- 1 Can you please give a more detailed explanation – gautham5678 Commented Sep 12, 2011 at 16:44
1 Answer
Reset to default 1Put it in the widget script file itself. This method will ensure that your script is loaded i the appropriate place of the DOM.
本文标签: phpLoad Javascript for a widget WordPress
版权声明:本文标题:php - Load Javascript for a widget WordPress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745559604a2663392.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论