implode(' ', $default_classes) ]; $attrs = wp_parse_args( $attrs, $defaults ); return wp_get_svg( $path, $attrs); } /** * Generic helper to modify the markup for a given path to an SVG * * @param string $path Absolute path to the SVG file * @param array $args Args to modify attributes of the SVG * @return string Inline SVG markup */ function wp_get_svg( $path = '', $attrs = array() ) { if ( ! $path ) { return; } $defaults = [ 'role' => 'image', 'class' => '', 'aria-labelledby' => 'title' ]; $attrs = wp_parse_args( $attrs, $defaults ); $role_attr = $attrs['role']; $class = $attrs['class']; if ( is_array( $class ) ) { $class = implode( ' ', $class ); } if ( file_exists( $path ) ) { $svg = file_get_contents( $path ); $svg = preg_replace( '/(width|height)="[\d\.]+"/i', '', $svg ); $svg = str_replace( '