get_template_directory and/or get_stylesheet_directory enqueuing wrong path

I am working on a local WordPress install and I am trying to enqueue some stylesheets like I’ve done many times before but I’ve never run into this bug before.

Here is my code in the functions.php file.

Read More
function foundation_styles() {
    wp_enqueue_style( 'foundation', get_template_directory() . '/css/foundation.css' );
}

add_action( 'wp_enqueue_scripts', 'foundation_styles' );

When viewing page source this is the file path that was enqueued:

<link rel='stylesheet' id='foundation-css'  href='http://localhost/FoundationwebsiteC:xampphtdocsFoundationwebsite/wp-content/themes/foundation/css/foundation.css?ver=4.0' >

Instead it should be:

<link rel='stylesheet' id='foundation-css'  href='http://localhost/Foundationwebsite/wp-content/themes/foundation/css/foundation.css?ver=4.0' >

Notice the C:xampphtdocsFoundationwebsite/ hidden in the middle of the file path.

The exact same thing happened when I used get_stylesheet_directory() instead of get_template_directory()

The filepath for my local install is:

C:xampphtdocsFoundationwebsitewp-contentthemesfoundationcss

Anyone know what is causing my filepath to be so funky?

Related posts

Leave a Reply

2 comments

  1. You’re using functions that will return a path whereas what you need is a URL.

    Replace get_template_directory() or get_stylesheet_directory() with get_template_directory_uri() or get_stylesheet_directory_uri().

    Example:

    function foundation_styles() {
        wp_enqueue_style( 'foundation', get_template_directory_uri() . '/css/foundation.css' );
    }