Skip to content
Permalink
Browse files

New filter wflux_css_theme_dependencies

New filter ‘wflux_css_theme_dependencies’ allows us to set CSS dependencies of style.css automatically, which then get loaded BEFORE style.css (using WP standard enqueue always loads them after style.css).

Saves overhead of using wp_dequeue_style() on your main style.css and then enqueing it again - that’s just spaghetti code!

NOTE: Requires an array to be supplied if using this filter as per standard WordPress enqueue_styles()

Example (functions.php - IMPORTANT ensure you have used wp_register_style() to register your additional CSS file first!):

add_filter( 'wflux_css_theme_dependencies', 'mywfx_style_dependencies' );
function mywfx_style_dependencies( $input ) {

	return array( 'my-css-file' );

}
  • Loading branch information...
Jonnyauk committed Aug 8, 2018
1 parent 35d22b6 commit c5dd3841e8404b71717ec8ce1f4266e98599fea8
Showing with 7 additions and 5 deletions.
  1. +2 −2 functions.php
  2. +5 −3 wf-includes/wf-display-functions.php
@@ -818,15 +818,15 @@
/**
* Inserts (enqueue) child theme CSS - style.css
* BACKPAT: When using WordPress 4.1 or above add_theme_support( 'title-tag' ) is automatically used instead.
*
* Filters available:
* wflux_css_theme_id - ID of file (main-theme)
* wflux_css_theme_path - full path to file
* wflux_css_theme_dependencies - other CSS dependencies, allows them to load before child theme style.css (array)
* wflux_css_theme_media - Media type
*
* @since 0.72
* @version 1.1
* @version 2.6
*
* @param none
*/
@@ -358,26 +358,28 @@ function wf_head_css_ie() {
/**
* Inserts (enqueue) child theme CSS - style.css
* BACKPAT: When using WordPress 4.1 or above add_theme_support( 'title-tag' ) is automatically used instead.
*
* Filters available:
* wflux_css_theme_id - ID of file (main-theme)
* wflux_css_theme_path - full path to file
* wflux_css_theme_dependencies - other CSS dependencies, allows them to load before child theme style.css (array)
* wflux_css_theme_media - Media type
*
* @since 0.72
* @version 1.1
* @version 2.6
*
* @param none
*/
function wf_head_css_theme() {
// Allow filtering
$id = apply_filters( 'wflux_css_theme_id', 'main-theme' );
$path = apply_filters( 'wflux_css_theme_path', WF_THEME_URL.'/style.css' );
$deps = apply_filters( 'wflux_css_theme_dependencies', false );
$media = apply_filters( 'wflux_css_theme_media', 'screen' );
wp_register_style( $id, $path, '', $this->wfx_mytheme_version_clean, $media );
wp_register_style( $id, $path, $deps, $this->wfx_mytheme_version_clean, $media );
wp_enqueue_style( $id );
}

0 comments on commit c5dd384

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.