Created
September 11, 2014 15:05
-
-
Save cassler/2b921b4dca032cc0e70d to your computer and use it in GitHub Desktop.
Simple Theme Images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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