\Granola\image();
will return the html for an img tag with an image from the assets/images
directory.
\Granola\image()
requires one parameter that specifies the name of the image to load, and accepts a second optional parameter, an array of attributes and their values to output on the img tag.
\Granola\image();
works with any image type and will always output an img
tag with the image specified.
<?php echo \Granola\image('example.jpg'); ?>
// will result in
<img src="https://example.com/wp-content/themes/granola/assets/images/example.jpg" alt="" role="presentation">
As mentioned, the second parameter allows for attributes to be applied to the image tag.
<?php echo \Granola\image('example.jpg', [
'alt' => 'this is alt text',
'class' => 'class-1 class-2'
]); ?>
// will result in
<img src="https://example.com/wp-content/themes/granola/assets/images/example.jpg" class="class-1 class-2" alt="this is alt text">