0

I have having an issue with the following code :

<!--CSS files -->
<?php

function my_styles_method() {
    // Register the style like this for a theme:  
    wp_register_style('my-custom-style', get_template_directory_uri() . '/includes/front-page.css');
    // enqueue the stule  
    wp_enqueue_style('my-custom-style');
    // Register the style like this for a theme:  
    if (is_page_template('our-story.php')) {
        wp_register_style('my-custom-style', get_template_directory_uri() . '/includes/main.css');
        // enqueue the stule  
        wp_enqueue_style('my-custom-style');
    }
}

add_action('wp_enqueue_scripts', 'my_styles_method');
?>

I am using the page template our-story.php and using the function as specified here :http://codex.wordpress.org/Conditional_Tags but somehow the main.css file doesn't get loaded. When I comment out the code for the front-page.css file and remove conditional statements than main.css files loaded and works correctly but not within this condition. I am not sure if I am using it correctly.

Looking forward to your response.

2 Answers 2

4

Why don't you use the body classes ? http://codex.wordpress.org/Function_Reference/body_class

You can target whatever page / template you want with those classes. Ex:

<body <?php body_class(); ?>>

On the homepage will give you :

<body class="home page page-id-14 page-template page-template-home-php ">

So, if you want specific CSS for homepage :

.home { Your styles }
Sign up to request clarification or add additional context in comments.

1 Comment

will try it out and let you know how it goes
-1

I think may use this.

if(is_page( 42 )) // id, title or slug name

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.