• Resolved Anne

    (@mellissaa)


    Hi i am using wordpress and am trying to use a different style sheet for my home page.
    Ive made a new header.php file in my child theme and added code that I found online which I thought should import my new style sheet mainstyle.css but it doesn’t work.

    help please.

    thanks

    http://utmcompass.com

Viewing 3 replies - 1 through 3 (of 3 total)
  • Using Firebug (with Firefox) or Chrome developer tools you will be able to see each different page has a different body class. You can style every item on each page as you wish within your child theme style.css using the body class e.g. in ‘twenty twelve’

    .home #site-navigation.main-navigation{
    	display:none;
    }

    will hide your main menu on the home page(if your blog is your home page), but not on other pages, which you probably won’t want to do, but is an example.
    I use this method to style pages differently, and prefer Firebug to Chrome for most things, as it has a useful ‘Copy CSS Path’ function when right clicking on an element which is very useful doing this sort of thing.
    You won’t need a separate style sheet this way.

    added code that I found online which I thought should import my new style sheet mainstyle.css

    please post the code.

    Hello Mellissaa,

    Hope you are doing well.

    If you have created separate template for your homepage and you have assigned it from dashboard -> setting -> reading -> front page

    Then please follow the code written below.


    function add_custom_stylesheet(){

    if( is_front_page() ){
    wp_enqueue_style( 'mycustomstyle', get_stylesheet_directory_uri().'/path/to/your/stylesheet' );
    }

    }
    add_action('wp_enqueue_scripts','add_custom_stylesheet');

    If you haven’t created any template and just using theme as it is (which I’m seeing on your site 😉 )

    Follow below mentioned code.


    function add_custom_stylesheet(){

    if( is_home() ){
    wp_enqueue_style( 'mycustomstyle', get_stylesheet_directory_uri().'/path/to/your/stylesheet' );
    }

    }
    add_action('wp_enqueue_scripts','add_custom_stylesheet');

    Please replace ‘/path/to/your/stylesheet’ by proper path according to your theme. get_stylesheet_directory_uri() will return the url up to your theme’s style.css and then you have to add relative path to your custom stylesheet.

    Hope this will help you.
    Let me know if any query. 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Different stylesheet for homepage’ is closed to new replies.