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 trial

WordPress

Luke Wenke
Luke Wenke
32,294 Points

Code 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
Luke Wenke
32,294 Points

Ok 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.

Nearly! You're missing the css folder in the path

wp_enqueue_style( 'my_plugin_frontend_css', plugins_url( 'my-plugin/css/front-end.css' ) );
Matt Campbell
Matt Campbell
9,767 Points

Check the file path. Need any slashes in there?

Luke Wenke
Luke Wenke
32,294 Points

Sorry I don't know what path to put in....

Luke Wenke
Luke Wenke
32,294 Points

I used the same code and got the same error....

Sean Templeton
Sean Templeton
12,983 Points

I 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'));
}

Remember 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
Sean Templeton
12,983 Points

I'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.

Watch 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
Sean Templeton
12,983 Points

Am I watching the right video?

Luke Wenke
Luke Wenke
32,294 Points

Hi could you specify the time in the video that that happens (minute:second)? Thanks!

Sean Templeton
Sean Templeton
12,983 Points

I am specifically looking at line 176 in that video. My line looks correct according to his as far as I can tell.

Luke Wenke
Luke Wenke
32,294 Points

That folder name isn't working

Sean Templeton
Sean Templeton
12,983 Points

How are you supposed to know what folder the plugin resides in? It doesn't tell you.

The 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?

Look at how Zac does the namespacing. Are their underscores? And if not what takes the place of the underscores?

Sean Templeton
Sean Templeton
12,983 Points

I tried this but it didn't work: plugins_url('my-plugin/front-end.css')

You'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
Sean Templeton
12,983 Points

Ok, 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
Sean Templeton
12,983 Points

Yeah, 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.

I understand your frustration. It took me a while to read between the lines. I'm just glad that you finally got the right answer.

DELETED!

DELETED!

Luke Briedis
Luke Briedis
3,600 Points

3 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
seal-mask
.a{fill-rule:evenodd;}techdegree
Jeremy Bray
Front End Web Development Techdegree Student 12,318 Points

I 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
PLUS
Sultan Alotaibi
Courses Plus Student 3,950 Points

I 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
STAFF
Zac Gordon
Treehouse Guest Teacher

Take 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
STAFF
Zac Gordon
Treehouse Guest Teacher

We're resolving the clarity of these questions.