Skip to content

Instantly share code, notes, and snippets.

@ulziibat-n
Forked from nicomollet/elementorcssinhead.php
Created September 10, 2019 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ulziibat-n/c9c642cb4c354d71ebf8b6cbd0532cfe to your computer and use it in GitHub Desktop.
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
<?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