Skip to content

Instantly share code, notes, and snippets.

@cassler
Created September 11, 2014 15:05
Show Gist options
  • Save cassler/2b921b4dca032cc0e70d to your computer and use it in GitHub Desktop.
Save cassler/2b921b4dca032cc0e70d to your computer and use it in GitHub Desktop.
Simple Theme Images
<?php
/**
* Simple function to streamline using image assets in your theme
*
* @author Darin Cassler
* @uses Wordpress
* @param string $src Required. The name of your image asset
* @param string $alt Optional. The alternate next for your img tag, if left blank - will use the image name.
* @param string $path Optional. This is the path inside your theme where images are stored. Defaults to /img/.
* @var $alt - Alt text for your image
*
**/
function theme_image($src, $alt = null, $path = null) {
// set defaults if path and alt are not passed
if ( null === $path ) { $path = 'img'; }
if ( null === $alt ) { $alt = $src; }
echo '<img src="' . get_template_directory_uri() . '/' . $path . '/' . $src . '" alt=' . $alt . '" />';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment