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.
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?
You’re using functions that will return a path whereas what you need is a URL.
Replace
get_template_directory()
orget_stylesheet_directory()
withget_template_directory_uri()
orget_stylesheet_directory_uri()
.Example:
use this
for more information refer this link
http://codex.wordpress.org/Function_Reference/wp_enqueue_style