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 am trying to create a shortcode that will return a link to a book on Amazon with a specific affiliate tracking code specific to the author. I created a user option called "amz" to hold the author's tracking code. This works fine when I'm using it elsewhere. This is the shortcode I created:

function amazon_link_function($atts, $content = null) { extract(shortcode_atts(array( 'isbn' => ' ', 'title' => ' ' ), $atts));

  $amztrack = the_author_meta( 'amz' );

  return '<a href="http://www.amazon.com/exec/obidos/ASIN/' .$isbn. '/' .$amztrack. '" title="' .$title. '" target="_blank">' .$title. '</a>';

} add_shortcode("amazon", "amazon_link_function");

The isbn and title values return properly, but the tracking code stored in the $amztrack variable is displayed as plain text before the paragraph the shortcode is used in:(

I also tired this for the return line and got the same result:

  return '<a href="http://www.amazon.com/exec/obidos/ASIN/' .$isbn. '/' .the_author_meta( 'amz' ). '" title="' .$title. '" target="_blank">' .$title. '</a>';
share|improve this question
up vote 1 down vote accepted

the_author_meta() prints the content immediately. Use instead:

$amztrack = get_the_author_meta( 'amz', FALSE );

This will return the value.

share|improve this answer
Boom! I havn't even finished editing the question for format and you solved it. Thanks! – JPollock Mar 1 '13 at 22:15

shortcodes need to return the value, therefore you cannot use a function which prints the output, like the_author_meta();

use get_the_author_meta() http://codex.wordpress.org/Function_Reference/get_the_author_meta

share|improve this answer

Your Answer


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

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