Dequeue Divi's external stylesheet and add it inline for pagination pages

56 Views Asked by At

I'm using the Divi plugin for WordPress and encountering an issue specifically on pagination pages. Divi has a feature "Load Dynamic Stylesheet In-line", however, this feature doesn't apply to pagination pages. Due to this limitation, I'm trying to implement a solution that dequeues the external Divi stylesheet and instead adds it inline only for pagination pages.

Here's the code I'm currently using:

// This function should add the Divi styles inline in the head of the document for pagination pages
function inline_divi_css_on_pagination_pages() {
    if (is_paged()) {
        $response = wp_remote_get('https://xxx.cz/wp-content/plugins/divi-builder/css/style-static.min.css?ver=4.17.4');
        if (!is_wp_error($response)) {
            $body = wp_remote_retrieve_body($response);
            echo '<style id="divi-builder-style-inline-inline-css" type="text/css">' . $body . '</style>';
        }
    }
}
add_action('wp_head', 'inline_divi_css_on_pagination_pages');

// This function should dequeue the Divi external stylesheet for pagination pages
function dequeue_divi_stylesheet_on_pagination_pages() {
    if (is_paged()) {
        wp_deregister_style('divi-builder-style-css');
        wp_dequeue_style('divi-builder-style-css');
    }
}
add_action('wp_enqueue_scripts', 'dequeue_divi_stylesheet_on_pagination_pages', 20);

Expected Result:

For pagination pages:

  1. The Divi external stylesheet link should be removed from the source.

  2. The styles from style-static.min.css should be added inline within a tag in the head of the document.

0

There are 0 best solutions below