clef/clef-wordpress

Remove unused css

Closed this issue · 8 comments

First off all: nice plugin, nice system. Good job.

This plugin does a good job including scripts when used and not include when not needed, a lot of plugins could learn from it. But there's one file that always stays: main.min.css. On every single page.

I don't use the badge on my website, so in my opinion, there's no need for the stylesheet to be there. It's not a big one, but I don't need it so I would like it to be gone.

The plugin should check if the badge is enabled, and if it isn't, the stylesheet shouldn't be included too.

More people share this opinion? You should reduce the amount of called files as low as possible, and this one is just hanging around there.

I fixed this 'issue' by doing this:

if ( !in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ) {
add_action('wp_print_styles', 'delete_clef_main', 100);
function delete_clef_main()  {
    wp_dequeue_style( 'wpclef-main' ); 
}}

Thanks @Tralapo! We include main.css for people including the badge HTML in a custom way — that said, we could definitely provide better optionality around whether to include the CSS.

+1 one to removing this on the front end by default. I think this probably should only be enqueued on login_enqueue_scripts for most sites.

If you need to load it for people who want to display the badge HTML, you could leave the style registered on wp_enqueue_scripts but forgo enqueuing it.

If there's a function or a method that loads the badge, you could possibly enqueue the script there so it's only present where it's needed.

+1 to having this optional / only loaded when needed.

Thanks for the solution @Tralapo!

Just opened up a PR which addresses this issue! Thanks for all the input here y'all.