Is it possible to switch entirely to GeneratePress + GenerateBlocks?

  • Pavlo Malynevskyi

    Hello,

    Is it practically possible to switch completely to the GeneratePress + GenerateBlocks combination, abandoning the standard WordPress and Gutenberg code, in order to maximize site performance?

    If so, what exactly should be added to functions.php?

    And in that case, how should one handle the standard blocks (tables, lists, etc.) that are not available in the GeneratePress + GenerateBlocks settings?

    Best regards,
    Pavlo

  • Hello Pavlo,

    Yes, this is a well-established approach and one that GP/GB is well-suited for. Since GenerateBlocks outputs minimal, semantic HTML with no frontend JavaScript overhead by default, sites built entirely with GP/GB typically score significantly better on Core Web Vitals than those relying on core blocks.

    To prevent Gutenberg’s block styles from loading on the frontend, you can add the following to your functions.php:

    add_action( 'wp_enqueue_scripts', function() {
        wp_dequeue_style( 'wp-block-library' );
        wp_dequeue_style( 'wp-block-library-theme' );
        wp_dequeue_style( 'global-styles' );
    }, 100 );

    Note that this removes those stylesheets globally, so if you do use any core blocks such as the Table block, they may render unstyled on the frontend and you’d need to add your own CSS for them.

  • Pavlo Malynevskyi

    Thank you for your quick response, George.

    After updating to WordPress version 7.0, global-styles-inline-css and classic-theme-styles-inline-css are still being loaded. Can you help me figure out how to deal with this?

    I would also like to suggest adding an option to GeneratePress/GenerateBlocks that allows disabling the global WordPress/Gutenberg styles.

  • Hi Pavlo,

    Those two are handled differently from the block library styles. You can extend the snippet with the following:

    add_action( 'wp_enqueue_scripts', function() {
        wp_dequeue_style( 'wp-block-library' );
        wp_dequeue_style( 'wp-block-library-theme' );
        wp_dequeue_style( 'global-styles' );
        wp_dequeue_style( 'classic-theme-styles' );
    }, 100 );

    Those two stylesheets are output by WordPress core via a separate code path, so the standard wp_dequeue_style() approach won’t remove them. The following should do the job:

    add_action( 'init', function() {
        remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
        remove_action( 'wp_footer', 'wp_enqueue_global_styles', 1 );
    } );
    
    add_filter( 'wp_theme_json_get_style_nodes', '__return_empty_array' );

    Regarding the feature request — thanks for the suggestion. You’re welcome to submit it at feedback.generatepress.com where it can be tracked and voted on by the community.

  • Pavlo Malynevskyi

    That worked. I really appreciate your help, George.

  • Ok, no problem!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.