The CSS file is never loaded
-
Hi
I can’t get the css file enqued on my site.
The file exists in the uploads folderI 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.
The topic ‘The CSS file is never loaded’ is closed to new replies.