madsrh123
Member
Posted 5 months ago #
Hi
I've written a plugin for my site and everything works fine, but sometimes when I refresh the site the plugin isn't loaded! The plugin loads a CSS file, so the site looks very ugly without the plugin.
Does anyone know why this happens?
Best regards
//MadsRH
How are you loading the CSS file? Are you using wp_enqueue_scripts or just adding it to the wp_head?
madsrh123
Member
Posted 5 months ago #
This is what I've got:
function add_my_stylesheet() {
echo "<link rel='stylesheet' href='".get_bloginfo('url')."/wp-content/plugins/arras-tweak/style.css'); ?>"; }
add_action('wp_head', 'add_my_stylesheet', 25);
See if this works better
add_action( 'wp_enqueue_scripts', 'add_my_stylesheet' , 25 );
function add_my_stylesheet() {
wp_register_style( 'arras-tweak', get_bloginfo( 'url' ) . '/wp-content/plugins/arras-tweak/style.css' );
wp_enqueue_style( 'arras-tweak' );
}
The , 25 will bump the style sheet down a little but if your CSS is unique then the order shouldn't really matter. If you need it to come later then leave it in.
There's a better way to get the current plugin directory name then hard coding it, but I've only had one cup of coffee this morning. :)
Also regarding your original problem, do you have an conditionals for when to add that style sheet? It maybe that the condition was preventing the wp_head addition from being called.
madsrh123
Member
Posted 5 months ago #
Jan Dembowski -> Thank you so much, I'll give it a try :-D
madsrh123
Member
Posted 5 months ago #
Not sure what you mean by
condition was preventing the wp_head addition from being called
By the way, I've got the same issue with a widget plugin I've written. This is the code I use to load the widget:
function sidebar_facebook_Init() {
register_widget('sidebar_facebook_Widget');
}
add_action('widgets_init', 'sidebar_facebook_Init');