• I am trying to add CSS to a custom archive page template that I created for a custom post type called Media (not the best name in retrospect, since it may be confused with WordPress’s built-in Media function).

    I have read the codex as well as every tutorial and support thread I can find on the wp_enqueue_styles function, but have not had any luck getting my CSS to communicate with my custom page template. I am relatively new to coding and entirely self-taught, so my apologies if the answer is glaringly obvious. Any help is greatly appreciated!

    Here is all the relevant info:

    Theme: Vantage child (built from Vantage)
    Page link: https://healthcareisahumanright.org/media/
    Page template: archive-media.php
    CSS stylesheet: archive-media.css

    Code in functions.php:

    $handle = 'media_style';
    wp_register_style( $handle, get_stylesheet_directory_uri().'/css/archive-media.css', array(), '', true );
    if ( is_page_template( 'archive-media.php' ) ) {
        wp_enqueue_style( $handle );
    }

    I have also tried this (as well as other variations):

    function wpse_enqueue_page_template_styles() {
        if ( is_page_template( 'archive-media.php' ) ) {
            wp_enqueue_style( 'archive-media', get_stylesheet_directory_uri() . '/css/archive-media.css' );
        }
    }
    add_action( 'wp_enqueue_scripts', 'wpse_enqueue_page_template_styles' );

    Additional info:
    I have a suspicion that the path I’m providing is part of the problem, since I have tried many variations of the above codes with no luck. I’m not sure if this is relevant, but I originally developed the site under a generic name (assigned by GoDaddy) since the organization for which I built the site had not yet decided on a domain name. My directory still uses this original name — the full path to my file is: /home/m8238269968/html/wp-content/themes/vantage-child/CSS/archive-media.css. Could this be messing up the get_stylesheet_directory_uri() in any way?

    On another note, I only have a couple things in my custom stylesheet right now because I want to test it and make sure it works before I write the CSS. I am unsure of how to check whether the stylesheet is linked properly, other than to see whether its contents affect my page.

  • The topic ‘Problem enqueueing additional stylesheet for custom page template’ is closed to new replies.