Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Correct PHP Syntax

I need to add this HTML tag:

<img src = "<?php echo esc_url( get_avatar_url( $post->post_author ) ); ?>" />

Inside PHP:

echo '<h3 class="nome-vendor-cat">',
    $current_cat->name,
    "&nbsp;di&nbsp;",
    '<a href="' . $vendor_link->get_shop_url() . '" class="nome-vendor">',
    get_usermeta( $post->post_author, 'dokan_store_name' ),
    '</span>',
    '</h3>';

I have to insert that image in PHP, but it always generates syntax errors.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Based on:

<img src = "<?php echo esc_url(get_avatar_url($post->post_author));?>" />

Detect the PHP part:

esc_url(get_avatar_url($post->post_author))

Detect the HTML part:

<img src = "
//and
" />

Write it in PHP:

echo '<img src = "'.esc_url(get_avatar_url($post->post_author)).'" />';

And you should better use . for concating things.
Its ok to use , when you echo stuff.
But if you replace echo with an assignment $var = , you have to replace all , with . to get it work again.
So always use ..

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading