I did a plugin who call enqueue style inside a shortcode. But when i add my shortcode in a text widget the enqueue style are not included en the page.
wp_enqueue_style('css-rfnb', RFNB_PLUGIN_DIR_URL . 'css/rfnb.css');
To properly include style you need to do it with wp_enqueue_scripts
action.
With a shortcode, you need to include the file differently as the header has already been send.
One way, Can be to include file in the shortcode. Other way, in the wp_enqueue_scripts
callback function can be to scan the_content
, detect shortcode and include the style like you've done.
If you make your own plugin, you can enqueue the style on each post conditionnaly with has_shortcode
function custom_shortcode_scripts(){
global $post;
if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'custom-shortcode') ) {
wp_enqueue_script( 'custom-script');
}
}
add_action( 'wp_enqueue_scripts', 'custom_shortcode_scripts');