• Resolved MTWK-IDG

    (@mtwk-idg)


    How do I add a style sheet ONLY to the home page. The style sheet is in the child theme directory.
    I’ve tried:

    add_action( ‘wp_enqueue_scripts’, ‘aimk_add_stylesheet’ );

    /**
    * Add stylesheet to the page
    */
    function aimk_add_stylesheet() {
    wp_enqueue_style( ‘masonryCSS’, get_stylesheet_directory_uri(‘homemasonry1540.css’, __FILE__) );
    }
    }

    I’ve tried with is_home in if statement but that didn’t work.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try this

    add_action( 'wp_enqueue_scripts', 'aimk_add_stylesheet' );
    
    function aimk_add_stylesheet() {
    
    	if(is_home()){
    	   wp_enqueue_style( 'homemasonry1540', get_stylesheet_directory_uri() . '/homemasonry1540.css '  );
    
    	}
    
    }

    get_stylesheet_directory_uri() gets the root url of the theme.
    I have tried it. and it works..

    Thread Starter MTWK-IDG

    (@mtwk-idg)

    That works except that is_home() didn’t work. I’m using a static page for a home page. home is being added as the body class. But is_home() is not recognizing this as home page.
    Got around it by pointing to the page id.

    Thanks for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add external style sheet from child theme to home page only’ is closed to new replies.