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

velochicdunord
velochicdunord
4,816 Points

Challlenge question 4 of 4 - Shortcodes

Stuck again. I know that the second item of my add_action statement isn't correct - but am not sure what I should be calling, as my choice paralleling the instruction videio isn't working? Insight? Help?

<?php
function my_plugin_shortcode( $atts, $content = null ) {

  global $post;

  extract( shortcode_atts( array(
    'num_courses' => '4',
    'tooltip' => 'on'
   ), $atts ) );

  if( $tooltip == 'on' ) $tooltip = 1;
  if( $tooltip == 'off' ) $tooltip = 0;

  $display_tooltip = $tooltip;

  //$options = get_options( 'my_plugin' );
  //$my_plugin_profile = $options( 'my_plugin_profile');

  ob_start();
  require( 'inc/front-end.php' );
  $content = ob_get_clean();
  return $content;
}

add_shortcode( 'my_plugin_shortcode', 'my_plugin_shortcode');
?>
plugin.php
<?php
function my_plugin_shortcode( $atts, $content = null ) {

  global $post;

  extract( shortcode_atts( array(
    'num_courses' => '4',
    'tooltip' => 'on'
   ), $atts ) );

  if( $tooltip == 'on' ) $tooltip = 1;
  if( $tooltip == 'off' ) $tooltip = 0;

  $display_tooltip = $tooltip;

  //$options = get_options( 'my_plugin' );
  //$my_plugin_profile = $options( 'my_plugin_profile');

  ob_start();
  require( 'inc/front-end.php' );
  $content = ob_get_clean();
  return $content;
}

add_shortcode( 'my_plugin_shortcode', 'my_plugin_shortcode');
?>

2 Answers

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

I just did the challenge & it tooke me a few tries. This is what worked for me:

<?php function my_plugin_shortcode($atts,$content=null) { return $content; } add_shortcode('$content');

?>

velochicdunord
velochicdunord
4,816 Points

Thanks - i wasn't picking up on that from the video.