Skip to content

Instantly share code, notes, and snippets.

@nicomollet
Last active December 6, 2022 09:21
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nicomollet/fc8a69b447f21cf8f4245f77d5a33d63 to your computer and use it in GitHub Desktop.
Save nicomollet/fc8a69b447f21cf8f4245f77d5a33d63 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' );
@webdevs-pro
Copy link

@amiad
Copy link

amiad commented Dec 6, 2022

thanks for your code.
\Elementor\Post_CSS_File need \Elementor\Core\Files\CSS\Post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment