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 trialRalph Johnson
10,408 PointsWordpress theme doesn't show up in dashboard
I have an index.php file and a style.css file in the wp-content/themes/my-theme/ directory on my local harddrive. WP opens at 127.0.1.1 in Chrome.
The theme does not show up in the dashboard for activation. What's up?
3 Answers
Tiffany McAllister
25,806 PointsDo you have the theme information as comments at the top of your stylesheet?
https://codex.wordpress.org/Theme_Development#Theme_Stylesheet
Tiffany McAllister
25,806 PointsIn the path to the Foundation stylesheet you just have a typo. It should be .css instead of .ccs
Ralph Johnson
10,408 PointsThanks! I'll see if that fixes it (looks like it's in more than one place). Now I just have to figure out what's up with the permissions for the js. I tried a couple of chmod workarounds but nothing's worked yet.
...looks like the main stylesheet (and app.js) is loading but foundation (both css and js, along with modernizr.js) still isn't.
Great catch, though...I didn't see the typo. Thanks again.
Tiffany McAllister
25,806 PointsIt's been a while since I've worked with WordPress so I'm a little bit fuzzy, but I think the argument after the path has to be an array:
https://codex.wordpress.org/Function_Reference/wp_enqueue_script#Using_a_Hook
Try that and see if it helps.
Ralph Johnson
10,408 PointsWhat the heck, here's the code (it's not that long).
<?php
function wprj_theme_styles() {
// wp_enqueue_style & get_template_directory_url = Wordpress functions/methods, not native PHP. dot is for concatenation.
wp_enqueue_style( 'foundation_css', get_template_directory_uri() . '/css/foundation.css');
// wp_enqueue_style( 'normalize_css', get_template_directory_uri() . '/css/normalize.ccs');
wp_enqueue_style( 'googlefont_css', 'http://fonts.googleapis.com/css?family=Asap:400,700,400italic,700italic');
wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css');
}
// add_action is a Wordpress function/method, not native PHP
add_action( 'wp_enqueue_scripts', 'wprj_theme_styles');
// wp_enqueue_script ( string $handle, string|bool $src = false, array $deps = array(), string|bool $ver = false, bool $in_footer = false )
// $in_footer==place the script in the footer (to run it after page loads) $ver=version $deps=dependencies
function wprj_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.min.js', array('jquery'), '', true );
wp_enqueue_script( 'main_js', get_template_directory_uri() . '/js/app.js', array('jquery', 'foundation.min.js'), '', true );
}
add_action( 'wp_enqueue_scripts', 'wprj_theme_js')
?>
The comments are notes to myself, to remember what's php and what's wordpress DSL. You'll note that I had already copied the syntax for wp_enqueue_script into a comment so I could refer to it. The arrays are there. I wonder if some of the empty strings need to be gotten rid of? That doesn't make sense (and Zac put them in there, so I guess they're supposed to be there) but since I'm trial-and-erroring anyway, who knows?
Ralph Johnson
10,408 PointsThanks for helping. Upvoted.
Tiffany McAllister
25,806 PointsTry this for your Modernizr script:
wp_enqueue_script( 'modernizr_js', get_template_directory_uri() . '/js/modernizr.js', array(), '', false );
I think you still need to add an empty array even though it's not dependant on any other script.
Ralph Johnson
10,408 PointsThat's also a good thought, which I'll keep in mind (in my "stuff to try in case stuff breaks" mental file)...but between the last message I posted and now, I downloaded and pasted new foundation files (css and js) just to see what would happen, and linked to a modernizr CDN instead of downloading a new modernizr (because modernizr is more complicated to dl due to its checkbox/custom nature, and I didn't know which options to pick because I don't know what it's being used for in this tutorial app). Everything just worked, no more worries. I think I got the idea from some obscure forum post (they were working with a production WP app on a remote server) where somebody suggested re-uploading the files in question. [sigh] This is why every coder wishes the error messages were better descriptors of what's going wrong.
Thanks for helping, hope your day goes well! :)
Ralph Johnson
10,408 PointsRalph Johnson
10,408 PointsYes, I had been saving files in the wordpress directory inside the home directory, instead of /var/www/html/wp-content. So I was saving the theme in the wrong place--I changed, and it worked. Now I'm trying to run Zac's Theme development tutorial, and
wp_enqueue_style( 'foundation_css', get_template_directory_uri() . '/css/foundation.ccs');
results in a 404 not found error, while
wp_enqueue_script( 'modernizr_js', get_template_directory_uri() . '/js/modernizr.js', '', '', false );
returns a 403 forbidden error. So there's no styling (and no js) and I can't figure out how to get those errors to go away. [sigh]...it's always something.