Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
If WP widget is active :
* @link
* In my class (the class that extends WP_Widget)
class My_Widget extends WP_Widget(){
public function __construct(){
/* some code blabla
add_action( 'wp_enqueue_scripts', array($this, 'my_callback') );
/* some code blabla
// enqueue styles for widget but only if it's there !
function my_callback(){
if( is_active_widget( false, false, $this->id_base, true ) ) {
wp_enqueue_style( 'handle', 'path/to/widget-styles.css' );
Copy link

thierrypigot commented May 28, 2015

Merci pour cette astuce ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment