how to use site_url for images in wordpress with php coding

<li><a href='#'>Core Transformation</a>
    <img alt='arrow' src=**'http://localhost/wordpress1/wp-content/themes/twentytwelve/images/header-triangle.png'** /></li>

 <li><a href=**'#'**>LINKS</a></li>

 <li><a href=**'#'**>Contact Us</a></li>

How can I replace the src and href using the site_url() function?

Related posts

Leave a Reply

4 comments

  1. You can use the following ways :

    <img src="<?php bloginfo('template_url'); ?>/images/image.jpg" />
    
    <img src="<?php echo get_template_directory_uri();?>/images/image.jpg" />
    
    <img src="<?php home_url();?>/images/image.jpg" />
    
    <img src="<?php echo site_url();?>/images/image.jpg"/>
    

    you can do it same for href

    More details refer codex

  2. <img src="<?php echo site_url();?>/images/image.jpg"/>
    

    or a better option would be:

    <img src="<?php bloginfo('template_url'); ?>/images/image.jpg" />
    

    You can do similarly for href

  3. site_url() is used to append text on url.. so if you want to navigate to your directory and fetch something you can use it like this..

    site_url(‘/images/default.jpg’);