It's because that's not how you should include an SVG in PHP,
include_once is used for including PHP files.
Reason behind this error:
PHP Parse error: syntax error, unexpected version (T_STRING)
is that PHP was unable to parse the beginning of the SVG file at the point where the XML version was defined:
<?xml version="1.0" encoding="utf-8"?>
Solution 1: To fix this, just remove the XML header tag from your SVG file completely.
Solution 2: Follow these tutorials. (Recommended)
- The Perfect WordPress Inline SVG Workflow
- Using Inline SVG Sprites in WordPress Themes
This is a much better way of including SVGs in your themes.
Both of them explain the same concept.
These tutorials will help you understand how to include an SVG in PHP in WordPress.
Now how to include them after the body tag?
This requires for you to use these tutorials in your theme files where appropriate.
For instance, if your theme opens the body tag in
index.php you'll need to modify
index.php and include the SVGs there.
<?php echo file_get_contents("filename.svg"); ?>
You can just echo the contents of your SVG file wherever you want in your HTML section of your PHP file.
However, playing with theme files requires PHP and WordPress knowledge to some extent.