Skip to Content
Docs
Snippets
SVGs

SVG Tips and Tricks

Using Uploaded SVGs

Our stack enables secure SVG uploads to WordPress, which is typically disabled by default.

add_filter('graphql_register_types', function () { register_graphql_field('MediaItem', 'svgContent', [ 'type' => 'String', 'description' => __('The raw SVG content of the media item', 'your-textdomain'), 'resolve' => function ($mediaItem) { $filePath = get_attached_file($mediaItem->ID); if (preg_match('/\.svg$/i', $filePath) && file_exists($filePath)) { return file_get_contents($filePath); } return null; } ]); });
Last updated on