improve & simplify inline svg handling
This commit is contained in:
parent
ac64cafac7
commit
9c38938bf4
3 changed files with 28 additions and 18 deletions
|
@ -25,13 +25,14 @@ function inline_svg(
|
|||
$svg_role_img = false,
|
||||
$svg_aria_hidden = true) {
|
||||
$svg_content = file_get_contents( get_template_directory_uri() . '/dist/images/' . $svg_name . '.svg' );
|
||||
$to_replace = $svg_class == '' ? 'class="{{class-name}}"' : '{{class-name}}';
|
||||
$to_replace = $svg_class == '' ? 'class="{{class-placeholder}}"' : '{{class-placeholder}}';
|
||||
$svg_content = str_replace($to_replace, $svg_class, $svg_content);
|
||||
$svg_content = $svg_role_img ? str_replace('<svg ', '<svg role="img" ', $svg_content) : $svg_content;
|
||||
$svg_content = $svg_aria_hidden ? str_replace('<svg ', '<svg aria-hidden="true" ', $svg_content) : $svg_content;
|
||||
$svg_title = $svg_title == '' ? '' : '<title>' . $svg_title . '</title>';
|
||||
$svg_content = substr_replace($svg_content, $svg_title, strpos($svg_content,'>') + 1, 0);
|
||||
return '<div class="' . $div_class . '">' . $svg_content . '</div>';
|
||||
$svg_content = $div_class == '' ? $svg_content : '<div class="' . $div_class . '">' . $svg_content . '</div>';
|
||||
return $svg_content;
|
||||
};
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue