-
-
Save ulziibat-n/c9c642cb4c354d71ebf8b6cbd0532cfe 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 hidden or 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