Created
May 19, 2018 23:29
-
-
Save nootrope/b48ff692f41cf5967e22a8aa588c032d to your computer and use it in GitHub Desktop.
WordPress enqueue styles by template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*** | |
From: https://developer.wordpress.org/reference/functions/wp_enqueue_style/ | |
This is a conditional loading of css file by page template (css will be loaded on on the pages with template-name.php). | |
You can change the condition to others. The code should be used in your theme’s function.php. | |
Notice: The code works for child themes. If you want to use it in a parent theme replace get_stylesheet_directory_uri() with get_stylesheet_uri(). | |
**/ | |
$handle = 'wpdocs'; | |
wp_register_style( $handle, get_stylesheet_directory_uri().'/relative/path/to/stylesheet.css', array(), '', true ); | |
if ( is_page_template( 'template-name.php' ) ) { | |
wp_enqueue_style( $handle ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment