0

I'm creating an author box for every WordPress post, and I'm trying to pull a link from the author meta.

This code works fine, and prints the (however unclickable) URL but I want to compile this into a clickable button like "Follow on Snapchat".

Can someone give me a push in the right direction?

<?php
$snapchat_profile = get_the_author_meta( 'snapchat_profile' );
    if ( $snapchat_profile && $snapchat_profile != '' ) {
     echo '<a href="' . esc_url(     the_author_meta('snapchat_profile')) . '"></a>';
    }

        ?>
  • echo '<a href="' . esc_url( $snapchat_profile ) . '">Follow on Snapchat</a>'; – Samuel Elh Nov 10 '16 at 0:13
0

You just created an empty link, it has correct link but no inner text:

echo '<a href="' . esc_url(     the_author_meta('snapchat_profile')) . '">Follow on Snapchat</a>';

And since you already stored the link in $snapchat_profile variable, no need to call the the_author_meta('snapchat_profile') function once again (it will only reduce in a few bits of extra memory usage and ..) so you should end up with this:

$snapchat_profile = get_the_author_meta( 'snapchat_profile' );
if ( $snapchat_profile ) {
    echo '<a href="' . esc_url( $snapchat_profile ) . '">Follow on Snapchat</a>';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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