• Resolved Henrik Gregersen

    (@henrikbonestdk)


    Hi

    I can’t get the css file enqued on my site.
    The file exists in the uploads folder

    I use the Astra theme so the style sheet is /uploads/so-css/so-css-astra.css

    The file exists, and I have debugged the code.

    You enqueu the style sheet in the wp-head action. Because of this and propably a plugin or other sort on my site the stylesheet is not loaded.

    If you move the style enqueu from the wp-head action to the wp_enqueu_scripts action then the stylesheet is loaded.

    i have done that by copying the code from the SiteOrigin_CSS.action_wp_head function to my functions.php file in the child theme and modified it like this :

    function so_css_get_latest_revision_timestamp() {
        if ($revisions  = get_option( 'siteorigin_custom_css_revisions[astra]' )) {
            krsort( $revisions );
            $revision_times = array_keys( $revisions );
    
            return $revision_times[0];
        } else {
            return '1.0.0';
        }
    }
    
    function child_enqueue_styles() {
    	// Enqueue the style sheet in the wp_enqueue_scripts instead of wp_head action
        $upload_dir = wp_upload_dir();
        $upload_dir_path = $upload_dir['basedir'] . '/so-css/';
    
        $css_file_name = 'so-css-astra';
        $css_file_path = $upload_dir_path . $css_file_name . '.css';
    
        if ( empty( $_GET['so_css_preview'] ) && ! is_admin() && file_exists( $css_file_path ) ) {
            wp_enqueue_style('my-so-css',
                set_url_scheme($upload_dir['baseurl'] . '/so-css/' . $css_file_name . '.css'),
                array(),
                so_css_get_latest_revision_timestamp()
            );
        }
    }
    
    add_action( 'wp_enqueue_scripts', 'child_enqueue_styles', 15 );
    

    After doing this the style sheet is loaded.

    Loading the style sheet in the wp-head action may work for most sites, but I am sure I have a plugin / theme combination that conflicts with this.

    But if the stylesheet loading is moved to the wp_enqueue_scripts action instead it will be more compatible I think.

    Please consider changing this in your plugin.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor alexgso

    (@alexgso)

    Hi Henrik,

    I’m unsure why your site ran into issues, but I can definitely see why the solution you used worked. For better compatibility overall, we’ll be making this change as there’s no real downside to switching hook.

    Plugin Support Andrew Misplon

    (@misplon)

    Pull Request: https://github.com/siteorigin/so-css/pull/76

    Thanks Henrik 🙂

    Thread Starter Henrik Gregersen

    (@henrikbonestdk)

    Well Thank you for implementing my suggestion. 🙂

    Plugin Support Andrew Misplon

    (@misplon)

    For sure. It, unfortunately, didn’t make the 1.5 release but I’ll do my best to get it into the next update, hopefully going out next week.

    Thread Starter Henrik Gregersen

    (@henrikbonestdk)

    I just checked the repository.

    The latest commit has reverted this change so its not included.

    Why?

    Plugin Support Andrew Misplon

    (@misplon)

    Hi Henrik

    Thanks for reaching out.

    Unfortunately, the commit caused a series of new support requests. There were unintended consequences that we weren’t able to resolve. As a result, we reverted the commit.

    Plugin Contributor alexgso

    (@alexgso)

    Hi Henrik,

    To add onto what Andrew said, the main reason why we can’t make this change is that other CSS (Additional CSS, themes, and plugins if not using wp_enqueue_scripts) is output after our CSS due to being output via WP_HEAD. This resulted in a large number of reports of users CSS not working after the update with this change included.

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

The topic ‘The CSS file is never loaded’ is closed to new replies.