Theme media assets and SVG icons

In a theme pattern PHP file to pull media you can either echo the url like this:

<img src="<?php echo esc_url( get_theme_file_uri("assets/media/content/404.png") ); ?>" alt="" class="wp-image-0123"/>

or use a function like this:

<?php
// in the functions.php file
function gomo_media( $file ) {
    return get_template_directory_uri() . '/assets/media/content/' . $file;
}
function gomo_icon( $file ) {
    return get_template_directory_uri() . '/assets/media/icon/' . $file;
}
<?php
// in the patterns/pattern.php file
?>
<img src="<?php echo esc_url( gomo_media("404.png") ); ?>" alt="" class="wp-image-0123"/>

the function can also be used for icons:

<?php 
// in the patterns/pattern.php file
?>
<span ><img src="<?php echo esc_url( gomo_icon("angel.svg") ); ?>" alt="" class="wp-image-0123456" width="60" height="60"/></span>

Search the site


Address

123 Main Street
Town
City
P05T C0D3

Tel: 01234 567 899

Mob: 01234 567 899

Email: ben@gomopress.com


Copyright 2023. Blah blah blah Company Limited