• Resolved deargeek

    (@deargeek)


    Is there a way (or could there be) to disable loading login-block-style.css when the block isn’t being used?

    I’m a PageSpeed Insights score junkie!

Viewing 1 replies (of 1 total)
  • Plugin Author Mustafa Uysal

    (@m_uysl)

    Hi @deargeek,

    Is there a way (or could there be) to disable loading login-block-style.css when the block isn’t being used?

    It’s already working that way! (I just tested with the default theme, and login-block-style.css is not loaded when the Magic Login block isn’t present on the page.)

    However, if you are using a classic theme WP enqueues block style globally (AFAIK). You can try something like this:

    function magic_login_maybe_dequeue_block_style() {
    	if ( is_admin() ) {
    		return;
    	}
    
    	// Get the current post content
    	global $post;
    
    	// If the post content doesn't contain the block, dequeue the CSS.
    	if ( $post && ! has_block( 'magic-login/login-block', $post ) ) {
    		wp_dequeue_style( 'magic-login-login-block' );
    	}
    }
    add_action( 'wp_enqueue_scripts', 'magic_login_maybe_dequeue_block_style', 20 );

    I hope this helps!

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.