Style and Script only on the widget page
Closed this issue · 3 comments
Mte90 commented
I've seen that the css and js are loaded in all the page of the dashboard but thery are needed only in the widget page.
i'ts possible add a check for this?
tommcfarlin commented
There are a couple of ways to do this, but your best bet is to probably use get_current_screen and use one of the properties available to sniff out which page you're on.
Mte90 commented
public function register_admin_styles() {
$screen = get_current_screen();
if ( 'widgets' == $screen->id ) {
wp_enqueue_style( $this->get_widget_slug() . '-admin-styles', plugins_url( 'css/admin.css', __FILE__ ) );
}
}
public function register_admin_scripts() {
$screen = get_current_screen();
if ( 'widgets' == $screen->id ) {
wp_enqueue_script( $this->get_widget_slug() . '-admin-script', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' ) );
}
}
It's possible add this in the boilerplate for all the developers?
tommcfarlin commented
No - this won't be made part of core because it's too niche.
As we continue to work on 3.0.0 and the documentation for it, though, this would be an example that we'd definitely have available.