-
-
Save anver/78398b1792ea447e28439c87301330a2 to your computer and use it in GitHub Desktop.
Load Elementor styles on all pages in the head to avoid CSS files being loaded in the footer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Load Elementor styles on all pages in the head to avoid CSS files being loaded in the footer | |
*/ | |
function elementor_css_in_head(){ | |
if(class_exists('\Elementor\Plugin')){ | |
$elementor = \Elementor\Plugin::instance(); | |
$elementor->frontend->enqueue_styles(); | |
} | |
if(class_exists('\ElementorPro\Plugin')){ | |
$elementor = \ElementorPro\Plugin::instance(); | |
$elementor->enqueue_styles(); | |
} | |
if(class_exists('\Elementor\Post_CSS_File')){ | |
$elementor_page_id = 3167; // Elementor page ID serving as a template (for a header or footer) | |
$css_file = new \Elementor\Post_CSS_File( $elementor_page_id ); | |
$css_file->enqueue(); | |
} | |
} | |
add_action( 'wp_enqueue_scripts', 'elementor_css_in_head' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment