top of page

Using SVG Code in WordPress which can also support animations.

  • Writer: سُلَيْمَان بْن دَاوُوْد
    سُلَيْمَان بْن دَاوُوْد
  • 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' )?>   


 
 
 

Recent Posts

See All
Duplicate Category in Wordpress

The following code helps to duplicate the default wordpress category by help of code. // Add Duplicate option for categories in WordPress...

 
 
 
C#.NET and Its Associated Codes

1- Creating an Desktop Application in C#.NET C# ADO.NET & MySQL MAIN C# and MySQL ADO.NET with Crystals Reports Ready Code 2- Handling...

 
 
 

Comments


© 2020 by syednazrulhassan

bottom of page