Skip to content

Instantly share code, notes, and snippets.

@norewp
Forked from nicomollet/elementorcssinhead.php
Created October 16, 2017 19:47
Show Gist options
  • Save norewp/32f9593c71c04ad13b4ecb825a21949f to your computer and use it in GitHub Desktop.
Save norewp/32f9593c71c04ad13b4ecb825a21949f to your computer and use it in GitHub Desktop.

Revisions

  1. @nicomollet nicomollet revised this gist Aug 24, 2017. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions elementorcssinhead.php
    Original file line number Diff line number Diff line change
    @@ -11,5 +11,11 @@ function elementor_css_in_head(){
    $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' );
  2. @nicomollet nicomollet created this gist Aug 24, 2017.
    15 changes: 15 additions & 0 deletions elementorcssinhead.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    <?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();
    }
    }
    add_action( 'wp_enqueue_scripts', 'elementor_css_in_head' );