Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to spice up a theme of mine with some shortcode buttons but I'm having quite a bit of trouble when trying to call the author's name within the button itself. I tried simply including

<?php echo do_shortcode('[button type="square" color="black" size="small"] Posted by <?php the_author(); ?> [/button]'); ?>

in the theme where I want the button with the author's name to appear, but it just gives a button that says 'Posted by '. I'm not the most experienced coder, but I know a little bit of everything from tinkering with various themes over the years. All help is appreciated, thanks in advance! -Matt

share|improve this question
    
I'm not that familiar (yet) with the internal functions of WordPress, but is do_shortcode supposed to be able to accept PHP tags <?php ... ?> inside of a string? –  Cupcake Jul 3 '11 at 4:39
add comment

migrated from stackoverflow.com Jul 3 '11 at 8:20

This question came from our site for professional and enthusiast programmers.

1 Answer

It looks like you're using a php tag within a php tag. I'd try something more like this...

<?php 
    echo do_shortcode('[button type="square" color="black" size="small"] Posted by '.get_the_author().' [/button]');
?>

or something like this...

<?php 
    $shortcode = '[button type="square" color="black" size="small"] Posted by '.get_the_author().' [/button]';
    echo "do_shortcode('$shortcode')";
?>
share|improve this answer
    
replace the_author() with get_the_author() in your answer, because you are using it in a concatenated string. –  Michael Jul 3 '11 at 10:19
    
Ah, good catch, fixed! –  jyoseph Jul 3 '11 at 15:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.