• Resolved Tim Boulley

    (@tboulley)


    I am trying to add a set image size to the following code and am not having much luck. Any help would be greatly appreciated.

    <?php
    	echo '<img src="' . esc_url( plugins_url( '/plugin-name/assets/img/image.png', ) ) . '" > ';
    	
    	?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Tim!

    It would be great if you could share a bit more information so that it’s possible to help you!

    1. What have you tried to set the image size? In the example you shared, you are only adding a src attribute. You might want to add a width or height. For example, if you want the image to have a fixed height of 300px you could do this: echo '<img src="' . esc_url( plugins_url( '/plugin-name/assets/img/image.png' ) ) . '" width="300"> ';
    2. Is there an error message? If yes, what does it say?
    3. What is the plugin-name in your example?
    4. In general, it is better to leave the image handling to WordPress itself. Is there any reason you could not use the Image block on your site?
    Thread Starter Tim Boulley

    (@tboulley)

    Hi Michal,

    Thank you very much for your quick response, and thank you for your suggestion, as that corrected the issue. I was using single quotes which was producing an error.

    Cheers!

    Glad I could help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Setting Image Size in PHP’ is closed to new replies.