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 How to Build a WordPress Plugin Building WordPress Widgets, and Shortcodes How to Create a WordPress Shortcode

Add a new shortcode named my_plugin_shortcode_name based on my_plugin_shortcode.

<?php
function my_plugin_shortcode( $atts, $content = null ){
    global $post;
    extract(shortcode_atts( array( 'num_courses' => '4' ) , $atts) );

   ob_start();
   require('inc/front-end.php');
   $content= ob_get_clean();
}
add_shortcode( 'my_plugin', 'my_plugin_shortcode' );

?>

I'm getting this response when I check the code: Bummer! The shortcode name should be passed as the first argument to add_shortcode.


Semi-frustrated that this code isn't passing since it's relatively a semantics error.

Can someone help me out.

Thanks in advance :)

4 Answers

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

It looks like the name "my_plugin" does not line up with the name said to use in the prompt.

valeriuv
valeriuv
20,999 Points

Does your function return anything? (hint)

Thank you for pointing that out! Unfortunately that still didn't allow me to pass the assignment. The error is truly in the add_shortcode() function

Awesome I don't know what I was thinking this is the fix, thanks zac

add_shortcode( 'my_plugin_shortcode_name', 'my_plugin_shortcode' );

Here is your answer bro,

add_shortcode( 'my_plugin_shortcode_name', 'my_plugin_shortcode' );