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 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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.