nathandrake
nathandrake

Reputation: 427

Adding custom stylesheet for different WordPress pages

I created custom home page whose name is "front-page.php" and than added another page with custom css and JS files like this in the header.php file:

<?php 
function my_styles_method() {
        
    if (is_page_template('front-page.php'==TRUE){  
    // Register the style like this for a theme:  
    wp_register_style( 'my-custom-style', get_template_directory_uri().'/includes/marquee.css');  

    // enqueue the stule  
    wp_enqueue_style( 'my-custom-style' );  
    
    }
    

    enter code here
    // Register the style like this for a theme:  
    if (is_page_template('our-story.php'==TRUE) {
    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' ); 

?>

Now, I face the following issues in this one: when I run this in WordPress I get this error message:

Parse error: syntax error, unexpected '{' in C:\wamp\www\wordpress_update\wp-content\themes\twentytwelve\header.php on line 32

I have created custom templates on both the pages .

Thank you in advance.

Upvotes: 1

Views: 600

Answers (1)

user1844933
user1844933

Reputation: 3427

Try this

<?php 
    function my_styles_method() {

        if (is_page_template('front-page.php')==TRUE){  
        // Register the style like this for a theme:  
        wp_register_style( 'my-custom-style', get_template_directory_uri().'/includes/marquee.css');  

        // enqueue the stule  
        wp_enqueue_style( 'my-custom-style' );  

        }


        //enter code here
        // Register the style like this for a theme:  
        if (is_page_template('our-story.php')==TRUE) {
        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' ); 

    ?>

// if (is_page_template('front-page.php'==TRUE) should be if (is_page_template('our-story.php')==TRUE)

Upvotes: 2

Related Questions