• Resolved finnsk3

    (@finnsk3)


    Hi, I am just wondering if I am doing something wrong here.
    In my functions.php I have the following:

    add_action('wp_footer', 'setup_css_js');
    
    function setup_css_js() {
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js', array(), '3.5.1', false);
        wp_enqueue_script('jquery');
    
        wp_enqueue_script('MobileMenu', THEME_STATIC . '/js/mobile-menu.js');
        wp_enqueue_script('dropdownContainer', THEME_STATIC . '/js/dropdown-container.js');
        wp_enqueue_script('searchTabs', THEME_STATIC . '/js/search-tabs.js');
        wp_enqueue_script('tileSlider', THEME_STATIC . '/js/tile-slider.js');
        wp_enqueue_script('artSlider', THEME_STATIC . '/js/art-slider.js');
        wp_enqueue_script('artGallery', THEME_STATIC . '/js/art-gallery.js');
        wp_enqueue_script('scrollToTop', THEME_STATIC . '/js/scroll-to-top.js');
        wp_enqueue_script('JS', THEME_STATIC . '/js/index.js');
    
        wp_enqueue_style('typography', THEME_STATIC . '/css/typography.css');
        wp_enqueue_style('bootstrap', THEME_STATIC . '/css/bootstrap.css');
        wp_enqueue_style('global', THEME_STATIC . '/css/global.css');
        wp_enqueue_style('custom_buttons', THEME_STATIC . '/css/buttons.css');
        wp_enqueue_style('container', THEME_STATIC . '/css/container.css');
        wp_enqueue_style('grid', THEME_STATIC . '/css/grid.css');
        wp_enqueue_style('art-slider', THEME_STATIC . '/css/art-slider.css');
        wp_enqueue_style('sidebar', THEME_STATIC . '/css/sidebar.css');
        wp_enqueue_style('header', THEME_STATIC . '/css/header.css');
        wp_enqueue_style('footer', THEME_STATIC . '/css/footer.css');
    }

    But even with these 3 settings enabled none of these files get minified:
    Optimise CSS Code
    Aggregate CSS-files
    Also aggregate inline CSS

    You can still see all of the css files being imported in the footed:

    <link rel='stylesheet' id='typography-css' href='/wp-content/themes/Libraries-Tasmania-Wordpress-Theme/static/css/typography.css?ver=6.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='bootstrap-css' href='/wp-content/themes/Libraries-Tasmania-Wordpress-Theme/static/css/bootstrap.css?ver=6.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='global-css' href='/wp-content/themes/Libraries-Tasmania-Wordpress-Theme/static/css/global.css?ver=6.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='custom_buttons-css' href='/wp-content/themes/Libraries-Tasmania-Wordpress-Theme/static/css/buttons.css?ver=6.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='container-css' href='/wp-content/themes/Libraries-Tasmania-Wordpress-Theme/static/css/container.css?ver=6.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='grid-css' href='/wp-content/themes/Libraries-Tasmania-Wordpress-Theme/static/css/grid.css?ver=6.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='art-slider-css' href='/wp-content/themes/Libraries-Tasmania-Wordpress-Theme/static/css/art-slider.css?ver=6.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='sidebar-css' href='/wp-content/themes/Libraries-Tasmania-Wordpress-Theme/static/css/sidebar.css?ver=6.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='footer-css' href='/wp-content/themes/Libraries-Tasmania-Wordpress-Theme/static/css/footer.css?ver=6.0.1' type='text/css' media='all' />

    Also all of the css files I am using within my custom blocks are also not being minified. Some css does just nothing that is declared via wp_enqueue_style within my theme.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    OK, two things to test:
    1. when adding to head instead of footer, does the CSS get aggregated?
    2. when using the full URL (so including the domain) in THEME_STATIC, does the CSS get aggregated?

    Thread Starter finnsk3

    (@finnsk3)

    Unfortunately not, I made the following changes:

    define('THEME_URL', get_template_directory_uri());
    define('THEME_DIR', get_template_directory());
    define('THEME_STATIC', THEME_URL . '/static');
    define('THEME_BLOCKS', THEME_URL . '/blocks');
    define('THEME_INC', THEME_DIR . '/includes');
    
    define('THEME_ALERT_TOKEN_OPTION', 'theme_alert_token');
    
    add_action('acf/init', 'my_acf_init_block_types');
    add_action('edit_form_after_editor', 'setup_css_js');
    add_action('wp_head', 'setup_css_js');
    
    function setup_css_js() {
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js', array(), '3.5.1', false);
        wp_enqueue_script('jquery');
    
        wp_enqueue_script('MobileMenu', THEME_STATIC . '/js/mobile-menu.js');
        wp_enqueue_script('dropdownContainer', THEME_STATIC . '/js/dropdown-container.js');
        wp_enqueue_script('searchTabs', THEME_STATIC . '/js/search-tabs.js');
        wp_enqueue_script('tileSlider', THEME_STATIC . '/js/tile-slider.js');
        wp_enqueue_script('artSlider', THEME_STATIC . '/js/art-slider.js');
        wp_enqueue_script('artGallery', THEME_STATIC . '/js/art-gallery.js');
        wp_enqueue_script('scrollToTop', THEME_STATIC . '/js/scroll-to-top.js');
        wp_enqueue_script('JS', THEME_STATIC . '/js/index.js');
    
        wp_enqueue_style('typography', 'https://tasedu-ltwww-aso-prod-app-staging.azurewebsites.net/wp-content/themes/Libraries-Tasmania-Wordpress-Theme/static/css/typography.css');
        wp_enqueue_style('bootstrap', THEME_STATIC . '/css/bootstrap.css');
        wp_enqueue_style('global', THEME_STATIC . '/css/global.css');
        wp_enqueue_style('custom_buttons', THEME_STATIC . '/css/buttons.css');
        wp_enqueue_style('container', THEME_STATIC . '/css/container.css');
        wp_enqueue_style('grid', THEME_STATIC . '/css/grid.css');
        wp_enqueue_style('art-slider', THEME_STATIC . '/css/art-slider.css');
        wp_enqueue_style('sidebar', THEME_STATIC . '/css/sidebar.css');
        wp_enqueue_style('header', THEME_STATIC . '/css/header.css');
        wp_enqueue_style('footer', THEME_STATIC . '/css/footer.css');
    }

    note typography.css is using fqdn, resulting html:
    <link rel=”stylesheet” id=”typography-css” href=”https://tasedu-ltwww-aso-prod-app-staging.azurewebsites.net/wp-content/themes/Libraries-Tasmania-Wordpress-Theme/static/css/typography.css?ver=6.0.1&#8243; type=”text/css” media=”all”>

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    weird … it’s still in the footer though?

    Thread Starter finnsk3

    (@finnsk3)

    Yes, which is rather odd.

    I tried this at the start of functions.php:

    add_action('wp_head', function() {
        wp_enqueue_style('global', 'https://tasedu-ltwww-aso-prod-app-staging.azurewebsites.net/wp-content/themes/Libraries-Tasmania-Wordpress-Theme/static/css/global.css');
    });

    It appeared in the footer, I then disabled autoptimize and it appeared in the head so autoptimize seems to be moving it in and attempt to stop render block.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    very weird, as there’s no “move CSS to footer” logic in AO (it _can_ defer, but does so leaving it where it is but loading the CSS as a print-stylesheet). Maybe you have some code snippet or another plugin acting on the CSS, but only in case of AO being active somehow?

    Thread Starter finnsk3

    (@finnsk3)

    No worries, I had a read through the plugin and fixed it.

    autoptimizeStyles.php line 312:
    $path = $this->getpath( $url );

    This always returns false for me so I just chucked in a simple fix:
    if (substr($url,-4) == ‘.css’) $path = ABSPATH . substr($url,1);
    else $path = $this->getpath( $url );

    I should have a look at why getpath is returning false here but it’s working for now so I will leave it at that.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    nice hack/ workaround 🙂

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘CSS/JS not being minified’ is closed to new replies.