WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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

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? – 40XUserNotFound Jul 3 '11 at 4:39

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

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

or something like this...

    $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

Your Answer


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