Echo an img and put in a php statement inside the src?

How would I format this correctly? I know I can’t open a php statement inside an existing one but I’m not sure how to correct it.

echo '<img src="<?php echo dirname( get_bloginfo('stylesheet_url') ); ?>/images/isa.jpg" alt="ISA">';

Related posts

Leave a Reply

4 comments

  1. I prefer to use PHP’s printf() and sprintf() for that. It’s easier to visualize the HTML and we just need to fill it with %s and their corresponding build up.

    printf(
        '<img src="%s/images/isa.jpg" alt="ISA">', // base HTML
        dirname( get_bloginfo('stylesheet_url') )  // first %s converted element
    );
    
  2. IT is better to use get_template_directory_uri() rather than get_bloginfo(). You can use following code:

    echo '<img src="'.get_template_directory_uri().'/images/isa.jpg" alt="ISA">';