0

I'm sure I'm missing something simple, as I rarely use shortcodes, but I can't seem to get the following shortcode to work.

I want it to be an "enclosing" short tag vs. a "self-closing", but its being treated as the latter.

[bio_image name="my name" title="my title"]
//image media in post content
[/bio_image]

with this functions.php code:

function bio_image_func( $atts, $content = null) {
    extract( shortcode_atts( array(
        'name' => 'employee',
        'title' => 'mastermind',
    ), $atts ) );
    return '<div class="team_photo"><p class="team_title"><span class="name">' . $name . '</span> <span class="title">' . $title . '</span></p>' . $content . '</div>';
}

add_shortcode( 'bio_image ', 'bio_image_func' );   

produces:

<div class="team_photo">
  <p class="team_title">
    <span class="name">my name</span> 
    <span class="title">my title</span>
  </p>
</div>

<img src="my_img_src" ... />

[/bio_image]

As you can see, the closing tag is just being printed out. Any suggestions?

for reference: the shortcode codex page

1 Answer 1

2

Remove the space after the shortcode name.

add_shortcode( 'bio_image ', 'bio_image_func' );

becomes

add_shortcode( 'bio_image', 'bio_image_func' );

I think WordPress is looking for a closing tag for bio_image[space], which doesn't exist.

1
  • 1
    lol sorry! You were right when you said "I'm sure I'm missing something simple" ;) Commented Jun 21, 2012 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.