Created
November 8, 2016 19:16
-
-
Save timwright12/8b51cf3439e764f4050017b7c5ac0930 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Create svg images | |
* | |
* @param string $name Icon name. | |
* @param array $opts Optional attributes. | |
* | |
* @return string | |
*/ | |
function svg_icon( $name, $opts = array() ) { | |
$href = get_stylesheet_directory_uri() . '/assets/icons/_defs/svg-defs.svg#icon-' . $name; | |
$role = empty( $opts['role'] ) ? 'image' : $opts['role']; | |
$height = empty( $opts['height'] ) ? '25' : $opts['height']; | |
$width = empty( $opts['width'] ) ? '25' : $opts['width']; | |
$class = empty( $opts['class'] ) ? 'icon icon-' . $name : 'icon ' . $opts['class']; | |
$label = ' aria-label="' . ( empty( $opts['label'] ) ? $name : $opts['label'] ) . '"'; | |
$label = 'presentation' === $role ? '' : $label; | |
return sprintf( '<svg role="%s" height="%s" width="%s" class="%s"%s><use xlink:href="%s"/></svg>', esc_attr( $role ), esc_attr( $height ), esc_attr( $width ), esc_attr( $class ), esc_attr( $label ), esc_url( $href ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment