help creating wordpress shortcode

Discussion in 'PHP' started by redlightshooter, Jul 28, 2010.

  1. #1
    hi, i need some help related to wordpress shordcode.
    I want to make a custom button shortcode
    here's the php code
    
    function button( $atts, $content = null ) {
    	extract(shortcode_atts(array(
    		'size'		=> 'large',
    		'url'		=> '#',
    	), $atts));
    	$out = "<a class=\"$size button \" href=\"$url\">" .do_shortcode($content). "<a/>" ;
    	return $out; 
    }
    add_shortcode('button', 'button');
    
    PHP:
    when i call the short code like [button]let's go[/button]
    the result i expected is like :
    
     <a class="large button" href="#">let's go</a>
    
    HTML:
    but what i got is with double <a> in the end of code:
    
     <a class="large button" href="#">let's go</a><a></a>
    
    HTML:
    does anybody can help me? what's wrong? Thanks in advance.
     
    redlightshooter, Jul 28, 2010 IP
  2. redlightshooter

    redlightshooter Greenhorn

    Messages:
    94
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    18
    #2
    ouch...., stupid me!!! just forget it it's just a misplaced character, i should put </a> not <a/> .

    Thanks.
     
    redlightshooter, Jul 28, 2010 IP