1

Im having a problem to register and load a gallery css code from my home page. Rest of the styles are loading fine, but this flexslider is not registering. Any guidance appreciated.

<?php 

function theme_styles() {

wp_enqueue_style ('normalize', get_template_directory_uri() . '/css/normalize.css');
wp_enqueue_style ('grid', get_template_directory_uri() . '/css/grid.css');
wp_enqueue_style ('main', get_template_directory_uri() . '/style.css');

wp_register_style( 'flexslider', get_template_directory_uri() . '/css/flexslider.css' );
if( is_page( 'home' ) ) {
    wp_enqueue_style( 'flexslider' );
}
}
add_action( 'wp_enqueue_scripts', 'theme_styles' );

// Enable custom menus
add_theme_support( 'menus' );

?>
  • Have you tried removing the conditional / what have you tried to solve this problem? – Howdy_McGee Nov 13 '13 at 22:06
  • Yes, I removed the conditional, did not work. – Linards Berzins Nov 13 '13 at 22:49
  • 3
    Maybe you really want to test for is_front_page(), not is_page('home'); is_front_page() tests for your static front page. – webaware Nov 13 '13 at 22:55
  • If you remove the conditional, is anything at all output? Or is the link output, but the stylesheet isn't loaded (e.g. 404)? Can we see a live link to the site demonstrating the problem? – Chip Bennett Nov 14 '13 at 0:52
  • Thank you for the suggestions, I will check those after office. Many thknks – Linards Berzins Nov 14 '13 at 10:27
3

The primary issue is an incorrect template conditional tag:

if( is_page( 'home' ) ) {}

This returns true if the current context is a static page, with the slug home. I presume that you're actually wanting to test for the Site Front Page - in which case you need to use the is_front_page() conditional:

if ( is_front_page() ) {
    wp_enqueue_style( 'flexslider' );
}

If the stylesheet still isn't being output, we'll need further debugging information.

  • You may also consider checking for is_home(), which looks for the blog index page. – Morgan Estes Nov 14 '13 at 3:55
  • Thank you for the suggestions, I will check those after office. Many thknks – Linards Berzins Nov 14 '13 at 10:28
  • Dear Chip Bennett, your solution worked like a charm, Thank you very much. – Linards Berzins Nov 15 '13 at 21:43
1

Try removing all points of failure and do what you know will work without any question. Then move forward from there one step at a time.

This is what I would do first just to make sure I am not completely insane!

<link type="text/css" href="<?php echo get_template_directory_uri(); ?>/css/flexslider.css">

Then if that is outputting then move forward. If not, fairly simple fix at that point. Coding really is full-time trouble shooting. :)

  • Thank you for the suggestions, I will check those after office. Many thknks – Linards Berzins Nov 14 '13 at 10:29
  • Why would you suggest the OP hard-code the stylesheet into the template instead of enqueueing it properly the OP is already doing? – s_ha_dum Nov 14 '13 at 14:51
  • Because this is a safe and "goof-proof" way to make sure that the file is indeed located in the correct dir. Its sort like calling the computer repair guy because your box wont boot.... and he asks if you have it plugged in. :) – Ryan Nov 14 '13 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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