If WP widget is active :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* @link http://codex.wordpress.org/Function_Reference/is_active_widget | |
* 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' ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Merci pour cette astuce ;)