Using SVG Code in WordPress which can also support animations.
- سُلَيْمَان بْن دَاوُوْد

- Jan 9, 2022
- 1 min read
Please add following code in active theme functions.php
/* svg code render */
function get_svg_inline($path, $style = '') {
if ( stripos( $path, '://' ) !== FALSE ) {
$path = str_replace( get_bloginfo('url'), ABSPATH, $path );
$path = str_replace( '//', '/', $path );
}
$svg = file_get_contents($path);
if ( $style ) {
$svg = str_replace( '<svg ', '<svg class="icon" style="' . $style . '" ', $svg );
}
return $svg;
}
function svg_inline($path, $style = '') {
echo get_svg_inline($path, $style);
}and you can use it like this anywhere on template anywhere
<?php svg_inline( get_template_directory_uri() . '/app/images/loader.svg' )?> 
Comments