Support » Fixing WordPress » Best way to add css to individual pages

  • I’m really confused how to do this. I’m trying to add a custom css for just my home page. My first option was to do put this code in the header.php ….

    <?php if ( is_page('home')) { ?>
    <link href="<?php bloginfo('template_url'); ?>/home2.css" rel="stylesheet" type="text/css" />
    <? } else {} ?>

    this works however I keep reading that you should use wp_enqueue_styles so I tried this in my functioins.php and it doesn’t work….

    function home_css()
    {
    	if (is_page('home')) {
    	wp_register_style( 'settings-styles', get_template_directory_uri().'home2.css');
    	wp_enqueue_style( 'settings-styles');
    	}
    }
    add_action( 'template_redirect', 'home_css' );

    I’ve replaced ‘template_redirect’ with ‘init’, ‘wp_head’, ‘wp_print_styles’,

    Nothing works

    How do you use wp_enqueue_styles correctly?

  • The topic ‘Best way to add css to individual pages’ is closed to new replies.