Add custom css to a page template in wordpress

前端 未结 3 604
甜味超标
甜味超标 2021-02-18 15:26

Hi i need some help with the creation of a custom css file for my page template. There are many topics out there regarding this issue but with each thread i read i get mo

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-18 15:51

    How about this one?

     function my_custom_styles() {
    
        wp_register_style( 'custom-styles', get_template_directory_uri().'/lib/styles/custom-styles.css' ) );
    
        if ( is_home ) {
    
        wp_enqueue_style( 'custom-styles' );
        }
     }
    
     add_action( 'wp_enqueue_scripts', 'my_custom_styles' );
    

    I have tested all three answers from here; and all of them works great. Does anybody know which one is faster & better?

提交回复
热议问题