• Resolved thoughtwell

    (@thoughtwell)


    About to go crazy here. I want to call a stylesheet for my project custom post type pages that is unique to that page. For instance, my custom post type is ‘project’ and I am trying to call a specific stylesheet located in my child theme.

    Here is my function and implementation in my functions.php file:

    // Register and Enqueue Scripts
    function slay_enqueue_scripts() {
    
    	wp_register_script( 'slay-responsive-menu', get_stylesheet_directory_uri() . '/lib/js/responsive-menu.js', array( 'jquery' ), '1.0.0', true );
    	wp_enqueue_script('slay-responsive-menu');
    
    	if(get_post_type('project')) {
    		wp_register_style('project-style', get_stylesheet_directory_uri() . '/lib/css/project.css');
    		wp_enqueue_style('project-style');
    	}
    
    }
    
    // Implement enqueued scripts
    add_action( 'wp_enqueue_scripts', 'slay_enqueue_scripts' );

    My scripts load fine, but I can’t get the stylesheet to load into the head of my single-project.php page. Anyone have any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter thoughtwell

    (@thoughtwell)

    I’ve also tried it with is_page_template and still no luck. Variation:

    // Register and Enqueue Scripts
    function slay_enqueue_scripts() {
    
    	wp_register_script( 'slay-responsive-menu', get_stylesheet_directory_uri() . '/lib/js/responsive-menu.js', array( 'jquery' ), '1.0.0', true );
    	wp_enqueue_script('slay-responsive-menu');
    
    	if ( is_page_template( 'single-project.php' ) ) {
    		wp_register_style('project-style', get_stylesheet_directory_uri() . '/lib/css/project.css');
    		wp_enqueue_style('project-style');
    	}
    
    }
    
    // Implement enqueued scripts
    add_action( 'wp_enqueue_scripts', 'slay_enqueue_scripts' );
    Thread Starter thoughtwell

    (@thoughtwell)

    Finally figured this out. in the conditional, I was supposed to be using is_singular('project')
    within the if statement, as the single-cpt.php page is not actually a page template.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘conditional enqueue for single custom post type page template’ is closed to new replies.