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 trialLuke Wenke
32,294 PointsCode Challenge - Adding AJAX To Plugins on the Front-End
"Inside of the my_plugin_frontend_scripts function, enque a stylesheet named front-end.css with a handle of my_plugin_frontend_css"
It gives the following error: "Bummer! Make sure you have used the correct CSS file path and name."
<?php
function my_plugin_frontend_scripts() {
wp_enqueue_style( 'my_plugin_frontend_css', plugins_url('front-end.css'));
}
?>
16 Answers
Luke Wenke
32,294 PointsOk I got it! Firstly the folder used dashes rather than underscores. Then there is a subfolder that the style is in even though in the video he doesn't do it that way.
davpay
40,173 PointsNearly! You're missing the css folder in the path
wp_enqueue_style( 'my_plugin_frontend_css', plugins_url( 'my-plugin/css/front-end.css' ) );
Shai Yahav
7,153 PointsThanks!!!
Matt Campbell
9,767 PointsCheck the file path. Need any slashes in there?
Luke Wenke
32,294 PointsSorry I don't know what path to put in....
Luke Wenke
32,294 PointsI used the same code and got the same error....
Sean Templeton
12,983 PointsI don't think there is either: a) enough information to determine the correct path, or b) the challenge is broken. I've come across other code challenges where the information needed was not provided, but was able to figure it out anyway. This one I just can't get past. I've tried the aforementioned code, and this as well:
function my_plugin_frontend_scripts() {
wp_enqueue_style( 'my_plugin_frontend_css', plugins_url('my_plugin/front-end.css'));
}
Shawn Gregory
Courses Plus Student 40,672 PointsRemember what Zac said about namespacing and naming the plugin folder that contains the plugin. Also remember when learning CSS where you would put your stylesheets. With these piece of information, you should be able to now successfully answer the code challenge. It took me a while just putting stuff into the code and seeing if it works. I finally remembered these two pieces of information and it worked for me.
Sean Templeton
12,983 PointsI'm looking at this video: http://teamtreehouse.com/library/how-to-build-a-wordpress-plugin/building-wordpress-widgets-and-shortcodes/adding-custom-styles-to-plugin-front-end at 4:40 and I can't see how my above code could possibly be wrong. Unless of course the plugin folder is not "my_plugin", in which case there is not enough information to complete the challenge.
Shawn Gregory
Courses Plus Student 40,672 PointsWatch how Zac references the plugin directory name when he points to something inside the plugin's directory. Don't know much more to say without giving the answer away.
Sean Templeton
12,983 PointsAm I watching the right video?
Luke Wenke
32,294 PointsHi could you specify the time in the video that that happens (minute:second)? Thanks!
Sean Templeton
12,983 PointsI am specifically looking at line 176 in that video. My line looks correct according to his as far as I can tell.
Luke Wenke
32,294 PointsThat folder name isn't working
Sean Templeton
12,983 PointsHow are you supposed to know what folder the plugin resides in? It doesn't tell you.
Shawn Gregory
Courses Plus Student 40,672 PointsThe name of the folder is in the function names that you've been coding all along. What does all of the function names have in common?
Sean Templeton
12,983 Pointsmy_plugin?
Shawn Gregory
Courses Plus Student 40,672 PointsLook at how Zac does the namespacing. Are their underscores? And if not what takes the place of the underscores?
Sean Templeton
12,983 PointsI tried this but it didn't work: plugins_url('my-plugin/front-end.css')
Shawn Gregory
Courses Plus Student 40,672 PointsYou're in the right direction. Remember you are trying to point to a stylesheet file. Where do you usually put all stylesheet files in a website. Once you answer that question, you will be able to answer this code challenge.
Sean Templeton
12,983 PointsOk, I got it now, but that doesn't make sense if you follow the videos or previous tutorials. He never does that in the videos (although I think he should have organized everything better). I think this coding challenge is a bit misleading.
Sean Templeton
12,983 PointsYeah, I really think it's not fair now. The next question is more along the lines of what information should be given. Totally not fair.
Shawn Gregory
Courses Plus Student 40,672 PointsI understand your frustration. It took me a while to read between the lines. I'm just glad that you finally got the right answer.
Shawn Gregory
Courses Plus Student 40,672 PointsDELETED!
Shawn Gregory
Courses Plus Student 40,672 PointsDELETED!
Luke Briedis
3,600 Points3 months later, I had to find this thread.....I had to look at the WP codex to properly figure out how to reference the plugin directory inside a plugin, so I eventually got past stage 3.
Jeremy Bray
Front End Web Development Techdegree Student 12,318 PointsI am not sure if that was Zac's intention but I have really learned a lot by referring to the codex when having issues with question answers, as web developers/ designers that whole frustration before breakthrough is probably the best lesson you can learn here.
Sultan Alotaibi
Courses Plus Student 3,950 PointsI received this message "Bummer! Make sure you have used the correct CSS file path and name.".
Can anyone check my code below where is the mistake?
wp_enqueue_style( 'my_plugin_frontend_css', plugins_url('my-plugin/front-end.css'));
Zac Gordon
Treehouse Guest TeacherTake a look at the code challenge again. We made some small updates, and you should have all the information you need for the correct answer.
Zac Gordon
Treehouse Guest TeacherWe're resolving the clarity of these questions.