Skip to content

Instantly share code, notes, and snippets.

@addisonhall
Last active April 23, 2020 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save addisonhall/e556671f1933e692096695314d27d581 to your computer and use it in GitHub Desktop.
Save addisonhall/e556671f1933e692096695314d27d581 to your computer and use it in GitHub Desktop.
Wordpress: Enqueue CSS for custom post type only
<?php
/**
* Enqueue specific CSS styles or javascript for a custom post type (cpt).
*/
add_action( 'wp_enqueue_scripts', 'my_cpt_scripts' );
function my_cpt_scripts() {
if ( is_singular( 'custom_post_type_name' ) || is_post_type_archive( 'custom_post_type_name' ) ) {
wp_enqueue_style( 'cpt-style', get_stylesheet_directory_uri() . '/css/your-cpt-style.css', false, '', 'all');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment