Determine whether a WordPress gadget is enabled

Judge whether a gadget is enabled and load the corresponding JS script and style of the gadget on demand.

Take WP default search widget as an example:

if ( is_active_widget( ”, ”, ‘search’ ) ) {
//Enabled, loaded JS script and style
} else {
//Not enabled
}

Example: there will be a prompt after the search widget is enabled.

function check_ widget() {
if( is_active_widget( ”, ”, ‘search’ ) ) {
Echo ‘< script > alert (“gadget enabled”)’;
}
}
add_ action( ‘wp_footer’, ‘check_widget’ );

Leave a Comment