treehouse : what would you like to learn today?
Web Design Web Development iOS Development

shortcode isn't working

  • In WordPress. Got this shortcode in my functions.php

    function amaranthe_buy_tickets( $atts, $content = null ) {
      extract(shortcode_atts(array(
      'link'  => '#',
      'target'  => '',
      'variation' => '',
      'size'  => '',
      'align' => '',
      ), $atts));
    
    $style = ($variation) ? ' '.$variation. '_gradient' : '';
    $align = ($align) ? ' align'.$align : '';
    $size = ($size == 'large') ? ' large_button' : '';
    $target = ($target == 'blank') ? ' target="_blank"' : '';
    
    $out = '<a' .$target. ' class="tickets_btn' .$style.$size.$align. '" href="' .$link. '">' .$content. '</a>';
    
          return $out;
        }
       add_shortcode('buy-tickets', 'amaranthe_buy_tickets');
    

    in my template file where I want the shortcode to display, I have this

       <?php echo do_shortcode("[buy-tickets]"); ?>
    

    and in the post, I have this

       [buy-tickets]Tickets[/buy-tickets]
    

    in the output, all I get is this

       <a href="#" class="tickets_btn"></a>
    

    for some reason, the content is missing.

  • Shouldn't your actual shortcode in the post be...

      [buy-tickets link="http://whateverlink.com"]Tickets[/buy-tickets]
    

    You are seeing the "#" because it is the default in the PHP

  • The link shows fine. It's the "Tickets" that isn't showing up. The content is missing

  • I just tested it, it is working for me. Are you by chance using this in a widget area? If so, you have to turn that on.

      add_filter('widget_text', 'do_shortcode');
    

    Otherwise, I am stumped. :/

  • Just to show you since I have it setup, it can be viewed here

    Obviously no styling... but hmm, has to be something else. :/

  • I don't know what the issue is either. The only thing I can think of it that it has something to do with how I am getting the posts

  • @cybershot did you checked your apache config file ? there is an option to enble shortcode