0

How would I go about including PHP within a printf that outputs an HTML link? The end goal is for the avatar to be clickable to go to the link.

This is what I've tried so far:

PHP print url code:

<?php printf( '<a href="%s"></a>', dokan_get_store_url( $author->ID )); ?>

Just to confirm I'm looking to combine the two lines of code so to speak so that the avatar code is within the URL code, the end result being the avatar becomes a link, hope that makes sense.

PHP get avatar:

<?php echo get_avatar( get_the_author_meta( 'user_email', get_the_author_meta( 'ID' ) ), 100, '', esc_html__( 'Author Avatar', 'multimarket' ), array( 'class' => 'author_avatar' ) ); ?>

How do I surround the avatar with the URL code so that the avatar becomes a link?

4
  • Format your code to make it readable. Commented Oct 31, 2017 at 13:32
  • What issues are you having with the above code? And what do you mean by "including PHP within an print that outputs a html link"? Commented Oct 31, 2017 at 13:32
  • He wants to combine the two so that the avatar is surrounded by the 'author ID' anchor tag. @MagnusEriksson Commented Oct 31, 2017 at 13:33
  • 1
    Ah. Well, then store the avatar in a variable instead of echo'ing it and add it to your printf() Commented Oct 31, 2017 at 13:35

1 Answer 1

1

You can do this:

<?php $avatar = get_avatar( get_the_author_meta( 'user_email', get_the_author_meta( 'ID' ) ), 100, '', esc_html__( 'Author Avatar', 'multimarket' ), array( 'class' => 'author_avatar' ) );

printf( '<a href="%s">%s</a>', dokan_get_store_url( $author->ID ), $avatar);

Then your avatar will be within the <a> tags.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.