Skip to main content
added 275 characters in body
Source Link
Andrea Puiatti
  • 335
  • 1
  • 3
  • 14

Theme looks ugly for the first 2 seconds- FOUC - stylesheets loaded in footer

My theme looks good and it works so far, but in the first seconds of loading the whole layout looks buggy: http://andreapuiatti.de/screenshots/cssstylebug.png

I think is because the css has been loaded with a delay but even positioning the wp_enqueue_style on the top of my functions.php doesn't make any difference

Any Idea on how to fix that?

Follows part of the functions.php

// Load Stylesheets
function addMyStyles() {

    wp_register_style('reset', get_template_directory_uri().'/reset.css');
    wp_register_style('style', get_template_directory_uri().'/style.css', array('reset') );

    wp_enqueue_style('style');

}
add_action('wp_head', 'addMyStyles');

// Load Scripts
if ( !function_exists( 'core_mods' ) ) {
    function core_mods() {
        if ( !is_admin() ) {
            wp_deregister_script( 'jquery' );
            wp_register_script( 'jquery', ( "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ), false);
            wp_enqueue_script( 'jquery' );
        }
    }
    add_action( 'wp_enqueue_scripts', 'core_mods' );
}

function addMyScripts() {
    /*wp_register_script( 'modernizr', get_template_directory_uri().'/_/js/modernizr.js', null, false );
    wp_enqueue_script( 'modernizr' );*/

    wp_register_script( 'jwplayer', get_template_directory_uri().'/_/js/jwplayer.js', null, false );
    wp_enqueue_script( 'jwplayer' );

    wp_register_script( 'bootstrap', get_template_directory_uri().'/_/js/bootstrap.js', array('jquery'), false );
    wp_enqueue_script( 'bootstrap' );

    wp_register_script( 'spk_slide', get_template_directory_uri().'/_/js/slides.js', array('jquery'), false );
    wp_enqueue_script( 'spk_slide' );
}
//add_action('wp_enqueue_scripts', 'addMyScripts');

// Add slider to front page
function my_enqueue_stuff() {
  if ( is_front_page() ) {
    addMyScripts();
    }
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_stuff' );

SOLVED: after research I found out that that effect name is FOUC (flash of unstyled content). I just had to increase the priority of the function which is adding the stylesheets to get them added to the head section: add_action( 'wp_enqueue_scripts', 'core_mods','2' ).

Theme looks ugly for the first 2 seconds

My theme looks good and it works so far, but in the first seconds of loading the whole layout looks buggy: http://andreapuiatti.de/screenshots/cssstylebug.png

I think is because the css has been loaded with a delay but even positioning the wp_enqueue_style on the top of my functions.php doesn't make any difference

Any Idea on how to fix that?

Follows part of the functions.php

// Load Stylesheets
function addMyStyles() {

    wp_register_style('reset', get_template_directory_uri().'/reset.css');
    wp_register_style('style', get_template_directory_uri().'/style.css', array('reset') );

    wp_enqueue_style('style');

}
add_action('wp_head', 'addMyStyles');

// Load Scripts
if ( !function_exists( 'core_mods' ) ) {
    function core_mods() {
        if ( !is_admin() ) {
            wp_deregister_script( 'jquery' );
            wp_register_script( 'jquery', ( "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ), false);
            wp_enqueue_script( 'jquery' );
        }
    }
    add_action( 'wp_enqueue_scripts', 'core_mods' );
}

function addMyScripts() {
    /*wp_register_script( 'modernizr', get_template_directory_uri().'/_/js/modernizr.js', null, false );
    wp_enqueue_script( 'modernizr' );*/

    wp_register_script( 'jwplayer', get_template_directory_uri().'/_/js/jwplayer.js', null, false );
    wp_enqueue_script( 'jwplayer' );

    wp_register_script( 'bootstrap', get_template_directory_uri().'/_/js/bootstrap.js', array('jquery'), false );
    wp_enqueue_script( 'bootstrap' );

    wp_register_script( 'spk_slide', get_template_directory_uri().'/_/js/slides.js', array('jquery'), false );
    wp_enqueue_script( 'spk_slide' );
}
//add_action('wp_enqueue_scripts', 'addMyScripts');

// Add slider to front page
function my_enqueue_stuff() {
  if ( is_front_page() ) {
    addMyScripts();
    }
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_stuff' );

Theme looks ugly - FOUC - stylesheets loaded in footer

My theme looks good and it works so far, but in the first seconds of loading the whole layout looks buggy: http://andreapuiatti.de/screenshots/cssstylebug.png

I think is because the css has been loaded with a delay but even positioning the wp_enqueue_style on the top of my functions.php doesn't make any difference

Any Idea on how to fix that?

Follows part of the functions.php

// Load Stylesheets
function addMyStyles() {

    wp_register_style('reset', get_template_directory_uri().'/reset.css');
    wp_register_style('style', get_template_directory_uri().'/style.css', array('reset') );

    wp_enqueue_style('style');

}
add_action('wp_head', 'addMyStyles');

// Load Scripts
if ( !function_exists( 'core_mods' ) ) {
    function core_mods() {
        if ( !is_admin() ) {
            wp_deregister_script( 'jquery' );
            wp_register_script( 'jquery', ( "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ), false);
            wp_enqueue_script( 'jquery' );
        }
    }
    add_action( 'wp_enqueue_scripts', 'core_mods' );
}

function addMyScripts() {
    /*wp_register_script( 'modernizr', get_template_directory_uri().'/_/js/modernizr.js', null, false );
    wp_enqueue_script( 'modernizr' );*/

    wp_register_script( 'jwplayer', get_template_directory_uri().'/_/js/jwplayer.js', null, false );
    wp_enqueue_script( 'jwplayer' );

    wp_register_script( 'bootstrap', get_template_directory_uri().'/_/js/bootstrap.js', array('jquery'), false );
    wp_enqueue_script( 'bootstrap' );

    wp_register_script( 'spk_slide', get_template_directory_uri().'/_/js/slides.js', array('jquery'), false );
    wp_enqueue_script( 'spk_slide' );
}
//add_action('wp_enqueue_scripts', 'addMyScripts');

// Add slider to front page
function my_enqueue_stuff() {
  if ( is_front_page() ) {
    addMyScripts();
    }
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_stuff' );

SOLVED: after research I found out that that effect name is FOUC (flash of unstyled content). I just had to increase the priority of the function which is adding the stylesheets to get them added to the head section: add_action( 'wp_enqueue_scripts', 'core_mods','2' ).

added 1301 characters in body
Source Link
Andrea Puiatti
  • 335
  • 1
  • 3
  • 14

My theme looks good and it works so far, but in the first seconds of loading the whole layout looks buggy: http://andreapuiatti.de/screenshots/cssstylebug.png

I think is because the css has been loaded with a delay but even positioning the wp_enqueue_style on the top of my functions.php doesn't make any difference

Any Idea on how to fix that?

Follows part of the functions.php

// Load Stylesheets
function addMyStyles() {

    wp_register_style('reset', get_template_directory_uri().'/reset.css');
    wp_register_style('style', get_template_directory_uri().'/style.css', array('reset') );

    wp_enqueue_style('style');

}
add_action('wp_head', 'addMyStyles');

// Load Scripts
if ( !function_exists( 'core_mods' ) ) {
    function core_mods() {
        if ( !is_admin() ) {
            wp_deregister_script( 'jquery' );
            wp_register_script( 'jquery', ( "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ), false);
            wp_enqueue_script( 'jquery' );
        }
    }
    add_action( 'wp_enqueue_scripts', 'core_mods' );
}

function addMyScripts() {
    /*wp_register_script( 'modernizr', get_template_directory_uri().'/_/js/modernizr.js', null, false );
    wp_enqueue_script( 'modernizr' );*/

    wp_register_script( 'jwplayer', get_template_directory_uri().'/_/js/jwplayer.js', null, false );
    wp_enqueue_script( 'jwplayer' );

    wp_register_script( 'bootstrap', get_template_directory_uri().'/_/js/bootstrap.js', array('jquery'), false );
    wp_enqueue_script( 'bootstrap' );

    wp_register_script( 'spk_slide', get_template_directory_uri().'/_/js/slides.js', array('jquery'), false );
    wp_enqueue_script( 'spk_slide' );
}
//add_action('wp_enqueue_scripts', 'addMyScripts');

// Add slider to front page
function my_enqueue_stuff() {
  if ( is_front_page() ) {
    addMyScripts();
    }
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_stuff' );

My theme looks good and it works so far, but in the first seconds of loading the whole layout looks buggy: http://andreapuiatti.de/screenshots/cssstylebug.png

I think is because the css has been loaded with a delay but even positioning the wp_enqueue_style on the top of my functions.php doesn't make any difference

Any Idea on how to fix that?

My theme looks good and it works so far, but in the first seconds of loading the whole layout looks buggy: http://andreapuiatti.de/screenshots/cssstylebug.png

I think is because the css has been loaded with a delay but even positioning the wp_enqueue_style on the top of my functions.php doesn't make any difference

Any Idea on how to fix that?

Follows part of the functions.php

// Load Stylesheets
function addMyStyles() {

    wp_register_style('reset', get_template_directory_uri().'/reset.css');
    wp_register_style('style', get_template_directory_uri().'/style.css', array('reset') );

    wp_enqueue_style('style');

}
add_action('wp_head', 'addMyStyles');

// Load Scripts
if ( !function_exists( 'core_mods' ) ) {
    function core_mods() {
        if ( !is_admin() ) {
            wp_deregister_script( 'jquery' );
            wp_register_script( 'jquery', ( "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ), false);
            wp_enqueue_script( 'jquery' );
        }
    }
    add_action( 'wp_enqueue_scripts', 'core_mods' );
}

function addMyScripts() {
    /*wp_register_script( 'modernizr', get_template_directory_uri().'/_/js/modernizr.js', null, false );
    wp_enqueue_script( 'modernizr' );*/

    wp_register_script( 'jwplayer', get_template_directory_uri().'/_/js/jwplayer.js', null, false );
    wp_enqueue_script( 'jwplayer' );

    wp_register_script( 'bootstrap', get_template_directory_uri().'/_/js/bootstrap.js', array('jquery'), false );
    wp_enqueue_script( 'bootstrap' );

    wp_register_script( 'spk_slide', get_template_directory_uri().'/_/js/slides.js', array('jquery'), false );
    wp_enqueue_script( 'spk_slide' );
}
//add_action('wp_enqueue_scripts', 'addMyScripts');

// Add slider to front page
function my_enqueue_stuff() {
  if ( is_front_page() ) {
    addMyScripts();
    }
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_stuff' );
Source Link
Andrea Puiatti
  • 335
  • 1
  • 3
  • 14

Theme looks ugly for the first 2 seconds

My theme looks good and it works so far, but in the first seconds of loading the whole layout looks buggy: http://andreapuiatti.de/screenshots/cssstylebug.png

I think is because the css has been loaded with a delay but even positioning the wp_enqueue_style on the top of my functions.php doesn't make any difference

Any Idea on how to fix that?