Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKate Moore
22,916 PointsCSS file won't link... pointing to assets folder?
None of my styles are working. This is my php code:
<?php
function wpt_theme_styles() {
wp_enqueue_style( 'foundation_css', get_template_directory_uri() . '/css/foundation.css');
wp_enqueue_style('normalize_css', get_template_directory_uri() . '/css/normalize.css');
wp_enqueue_style( 'normalize_css', 'http://fonts.googleapis.com/css?family=Montserrat' );
wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css');
}
add_action( 'wp_enqueue_scripts', 'wpt_theme_styles' );
function wpt_theme_js() {
wp_enqueue_script( 'modernizr_js', get_template_directory_uri() . '/js/modernizr.js', '', '', false );
wp_enqueue_script( 'foundation_js', get_template_directory_uri() . '/js/foundation.js', array('jquery'), '', true );
wp_enqueue_script( 'main_js', get_template_directory_uri() . '/js/app.js', array('jquery', 'foundation_js'), '', true );
}
add_action( 'wp_enqueue_scripts', 'wpt_theme_js' );
?>
When I open it up on my site and inspect element it looks like it searching for the css here:
<link rel="stylesheet" href="assets/css/foundation.css">
I don't think I have an assets folder set up. How far back does get_template_directory_uri search? Is there a way to point to my file more specifically?
Edit: when I go into wp-admin and click on appearance > customize... the stylesheet shows up. But when I go to view site it's still missing! I'm thinking my get_template_directory_uri() is somehow pointing to an asset folder that isn't there. How can I redirect it to the correct path?
1 Answer
Rich Bagley
25,869 PointsHi Kate,
From that I can't spot the reason that the assets folder would be showing. By using get_template_directory_uri it should check the theme folder and therefore display wp-content > themes > theme-name-goes-here.
A few things to check:
- Do you see any errors at the bottom of the themes page within the admin?
- Do you have all the stylesheet header information in place?
- Have you replaced the default HTML in the header.php file with wp_head
Hope one of those helps :)
-Rich
EDIT: Can you check the Settings within your WP dashboard to make sure the home and site URLs are populated correctly please? It's a bit of an old post but this seems to have the same issue you have.
Kate Moore
22,916 PointsThanks, I have tried all of these but none of them seem to work... it still looks like it's pointing to the assets folder? Here is the site I'm working on if it might help: http://demo3.katemoore.io/
Rich Bagley
25,869 PointsWhen viewing the source code I can't see the assets folder but I can see that everything is repeated within the path, e.g.
http://example.com/wp-content/themes/theme-goes-here/wp-content/themes/theme-goes-here/css/foundation.css?ver=4.2.2
Can you post your stylesheet header please?
Also, just checking, when changing index.php, have you been doing so within your theme folder?
Thanks
-Rich
Kate Moore
22,916 Points/*
Theme Name: Treehouse Portfolio
Author: Kate Moore
Author URI: http://demo3.katemoore.io/
Description: My super spectacular first theme ever!
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: black, brown, orange, tan, white, yellow, light, one-column, two-columns, right-sidebar, flexible-width, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, translation-ready
Text Domain: Kate Moore!
This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/
I have been uploading my index.php file to the treehouse-portfolio
Rich Bagley
25,869 PointsI can't spot anything obvious from your code but just edited my answer above with another update.
-Rich
Kate Moore
22,916 PointsIt's working! I'm not really sure what I did... I followed that link and what you said and went into settings and re-copied the URL into the Wordpress address and Site address even though they looked correct. After logging out of wordpress, logging back in and hard refreshing the page a few times everything looks good! Maybe my browser was caching some old files... Thank you so much!
Rich Bagley
25,869 PointsHi Kate,
No problem. I have a feeling it could have been to do with the trailing slash in those URLs, e.g. example.com/ instead of just example.com.
Glad you're sorted either way :)
-Rich
Rich Bagley
25,869 PointsRich Bagley
25,869 PointsI've updated your question to include the markdown so others can see your code a little clearer :)
Here's how to do it if you need to do it in future.
-Rich