I'm using the PHP file_get_contents()
function to retrieve and echo the contents of an SVG-file.
<?php echo file_get_contents( get_stylesheet_directory_uri() . '/assets/images/Search_Glyph.svg' ); ?>
I checked the theme with the Wordpress.org theme checker and I am currently resolving all the issues. One of the issues is the use of file_get_contents
.
It gives me the following warning:
WARNING: file_get_contents was found in the file header.php File operations should use the WP_Filesystem methods instead of direct PHP filesystem calls.
I tried finding information about the $wp_filesystem
thing, but there is very little information available and even less examples (to be honest, I'm not totally sure if that's the correct function to use).
How can I use a Wordpress function to retrieve a file and echo the contents of it in a PHP-file?
I'm really at loss what I should do with this. All help is very much appreciated!
file_get_contents($path)
withWP_Filesystem_Direct::get_contents($path)
<?php echo WP_Filesystem_Direct::get_contents(get_stylesheet_directory_uri() . '/assets/images/Search_Glyph.svg'); ?>
but when I try to save it, it gives an error (I added it via the theme editor). The error is: (1)Uncaught Error: Class 'WP_Filesystem_Direct' not found in wp-content/themes/ambition-theme/header.php:133 Stack trace: #0 wp-includes/template.php(723): require_once() #1 wp-includes/template.php(672): load_template('/home/u36816p32...', true) #2 wp-includes/general-template.php(41): locate_template(Array, true) #3 wp-content/themes/ambition-theme/home.php(1): get_header() #4 wp-includes/template-loader.php(106): include('/home/u36816p32...') #5 wp-blog-header.php(19): require_once('/home/u36816p32...') #6 /home/u36816p32xxxx/domains/creativec
(2)