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 trialMaja B.
12,984 PointsChallenge Task 2 of 4 (How to Create a WP Shortcode)
Hi, please help me pass this challenge:
Inside of the my_plugin_shortcode function, pull in the global post variable. Then extract the num_courses attribute, setting it to a default value of 4.
<?php
function my_plugin_shortcode ($atts, $content = null) {
global $post;
extract (shortcode_atts( array(
'num_courses' => '4'
), $atts));
};
?>
Bummer! extract should be passed the return value of shortcode_atts directly.
4 Answers
Rich Bagley
25,869 PointsHi Maja,
Remove your space between extract and the opening ( and that should do it.
Thanks
-Rich
Renee Wilson
9,820 Points<?php function my_plugin_shortcode( $atts, $content = null ) { global $post; extract(shortcode_atts( array( 'num_courses' => '4' ), $atts) );
} Here's my answer. Make sure to take the 's' off the posts of global $posts
Tinashe Kingstone Jonhera
3,575 Points<?php
function my_plugin_shortcode ($atts, $content = null) { global $post; extract(shortcode_atts( array( 'num_courses' => '4' ), $atts)); }; ?>
Andres Ramirez
18,094 Points<?php
function my_plugin_shortcode ($atts, $content = null) {
global $post;
extract(shortcode_atts(array(
'num_courses' => '4'
), $atts));
};
?>
Maja B.
12,984 PointsMaja B.
12,984 Pointsgreat! thanks!
-Maja