Mathew
Mathew

Reputation: 13

PHP within Print PHP

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?

Upvotes: 0

Views: 86

Answers (1)

Albzi
Albzi

Reputation: 15609

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.

Upvotes: 1

Related Questions