img
— Get the URL to a local image file.
Summary
img()
is a helper function used to include an image from within a theme. It returns the URL to an image file located in the images directory of that theme, usually located in themes/YourTheme/images. The resulting path can be used in an <img> tag, or anywhere else an image URL is needed.
- img($file, $dir = 'images')
Get the URL to a local image file.
- Parameters:
$file (
string
) – Filename, including the extension.$dir (
string
) – Directory within the theme to look for image files. Defaults to ‘images’.
- Returns:
string
Usage
Examples
Use img()
to include a link to an image stored in themes/YourTheme/images
:
<?php
$themeScreenshot = img('fallback-theme.png');
?>
<div class="screenshot">
<img src="<?php echo $themeScreenshot; ?>" />
</div>