0

I'm sure this is simple but can anyone please help me find the correct code to centre the image in the below code

add_action('woocommerce_after_add_to_cart_button', 'add_content_on_add_to_cart_button');

function add_content_on_add_to_cart_button() {
    
      echo "<img src='image.png' width=70% >"; 
}

For context, this code is currently being used in a wordpress websites functions.php file. It is calling woocommerce hooks.

TIA

Johannes
  • 64,305
  • 18
  • 73
  • 130
Jake
  • 3
  • 1

1 Answers1

0

Use a style attribute within the img tag and use margin: 0 auto to center it horizontally (making a display: block definition necessary):

echo "<img src='image.png' style='display:block;margin: 0 auto;width: 70%;'>" ;

Or – in case of your given 70% width – just use margin-left: 15% within that style attribute instead of margin: 0 auto

Johannes
  • 64,305
  • 18
  • 73
  • 130