0

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' ).

2
  • 1
    Need to see a live example to really pin down this problem. Sounds like your CSS isn't loading in the <head> of your site so the content displays, then the CSS is loaded, then the browsers suddenly styles your page.
    – kingkool68
    Commented Aug 4, 2013 at 15:18
  • You should post that as a proper answer, but the core_mods function just hijacks the Core JQuery. I don't see how that alters where the stylesheet loads. Something is still missing.
    – s_ha_dum
    Commented Aug 5, 2013 at 13:42

1 Answer 1

0

Changing the position of wp_enqueue_style inside functions.php will make no difference at all. Scripts and styles are printed on a couple of hooks. Placement of the registration functions inside functions.php is not a factor.

Your stylesheets are loading in the footer. Neither wp_enqueue_style nor wp_register_style have an $in_footer parameter like wp_enqueue_script and wp_register-script.

I have to assume that your theme is loading the scripts manually hooked to wp_footer. Look for add_action('wp_footer',.

Please edit your question to include the code that includes the stylesheets. That will help with improving this answer.

10
  • no... as you can see I added the stylesheet on wp_head Commented Aug 4, 2013 at 18:06
  • and here the header which of course contains the wp_head() call jsfiddle.net/QVHSn Commented Aug 4, 2013 at 18:10
  • @AndreaPuiatti : When I look at the source, taken for the address bar in the image you posted, the stylesheets are in the footer. Look down around line 340 in the generated HTML.
    – s_ha_dum
    Commented Aug 4, 2013 at 18:13
  • @AndreaPuiatti : I admin that I don't know why the scripts are loading at the bottom. Something odd is happening somewhere in code not posted.
    – s_ha_dum
    Commented Aug 4, 2013 at 18:16
  • thank you but that's another website! Commented Aug 4, 2013 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.