admin管理员组文章数量:1130349
I am trying to write a widget and I need to add the color picker to my widget form. I want to add the script only on widget.php page and not on all the admin pages.
Is there a way that I can detect the page inside the construct function of my widget? If not how I can include the script only when I'm on widget.php page?
I am trying to write a widget and I need to add the color picker to my widget form. I want to add the script only on widget.php page and not on all the admin pages.
Is there a way that I can detect the page inside the construct function of my widget? If not how I can include the script only when I'm on widget.php page?
Share Improve this question asked Nov 4, 2018 at 17:18 agahiagahi 1013 silver badges12 bronze badges1 Answer
Reset to default 2You may use the global variable $pagenow to figure out if you are on a particular admin page, in your case this would be checking if you are on the widgets.php admin page:
<?php
global $pagenow;
if( $pagenow === 'widgets.php' ) {
?>
<script>
// JavaScript goes here
</script>
<?php
}
Furthermore, it will be helpful for you to use the plugin Query Monitor so that you may easily find out what conditionals may be used on a particular instance.
I am trying to write a widget and I need to add the color picker to my widget form. I want to add the script only on widget.php page and not on all the admin pages.
Is there a way that I can detect the page inside the construct function of my widget? If not how I can include the script only when I'm on widget.php page?
I am trying to write a widget and I need to add the color picker to my widget form. I want to add the script only on widget.php page and not on all the admin pages.
Is there a way that I can detect the page inside the construct function of my widget? If not how I can include the script only when I'm on widget.php page?
Share Improve this question asked Nov 4, 2018 at 17:18 agahiagahi 1013 silver badges12 bronze badges1 Answer
Reset to default 2You may use the global variable $pagenow to figure out if you are on a particular admin page, in your case this would be checking if you are on the widgets.php admin page:
<?php
global $pagenow;
if( $pagenow === 'widgets.php' ) {
?>
<script>
// JavaScript goes here
</script>
<?php
}
Furthermore, it will be helpful for you to use the plugin Query Monitor so that you may easily find out what conditionals may be used on a particular instance.
本文标签: pluginsHow to check if you are on widgetphp page
版权声明:本文标题:plugins - How to check if you are on widget.php page? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749205719a2332497.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论