skip to Main Content

Hi I am adding a little woo hook in a child theme, to echo a free shipping banner, having problem with the path to image, which is next to the functions.php file in the theme root.

    function denzilla_add_below_prod_meta() {
   echo '<div class="free-shipping" style="background: #fdfd5a; margin-top: -5px; margin-bottom: 15px">';
   echo 'img src="free.jpg" />';
   echo '</div>';
}

is the function, but am just getting the text "img src="free.jpg" />" output on front end page instead of the actual image.

Any tips on the correct path (both files are next to each other in theme root) or maybe one of the get_theme_url or similar hooks to do it?

text front end

Thanks

2

Answers


  1. Update your code with these 2 things

    1. Your img tag looks broken, so please update it like echo ”;
    2. Use get_template_directory_uri() to get the image path
    Login or Signup to reply.
  2. <?php 
    function denzilla_add_below_prod_meta() {
        echo '<div class="free-shipping" style="background: #fdfd5a; margin-top: -5px; margin-bottom: 15px">';
        echo '<img src="' . get_template_directory_uri() . '/images/free.jpg" />';
        echo '</div>';
      }
      add_action('woocommerce_single_product_summary', 'denzilla_add_below_prod_meta', 25);
      
    ?>  
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search