getAttribute( 'src' ) ); if ( ! file_exists( $src ) ) { return $content; } $svg_dom = dom( file_get_contents( $src ) ); $svg_element = get_dom_element( 'svg', $svg_dom ); $svg_node = $dom->importNode( $svg_element, true ); $parent = $link ?? $figure; $parent->appendChild( $svg_node ); $svg = get_dom_element( 'svg', $parent ); $svg->setAttribute( 'xmlns', 'http://www.w3.org/2000/svg' ); $width = $img->getAttribute( 'width' ) ? $img->getAttribute( 'width' ) : ''; $height = $img->getAttribute( 'height' ) ? $img->getAttribute( 'height' ) : ''; $fill = $img->getAttribute( 'fill' ) ? $img->getAttribute( 'fill' ) : ''; $viewBox = $svg_element->getAttribute( 'viewBox' ) ? $svg_element->getAttribute( 'viewBox' ) : ''; if ( $width ) { $svg->setAttribute( 'width', $width ); } if ( $height ) { $svg->setAttribute( 'height', $height ); } if ( $fill ) { $svg->setAttribute( 'fill', $fill ); } if ( $viewBox ) { $svg->setAttribute( 'viewBox', $viewBox ); } foreach ( $svg_element->childNodes as $child ) { $imported = $dom->importNode( $child, true ); $svg->appendChild( $imported ); } $img->parentNode->removeChild( $img ); return $dom->saveHTML(); }