Home › Forums › Feature Requests › File field type: Option to return SVG as code › Reply To: File field type: Option to return SVG as code
I was looking for this exact answer! Thanks! However, I need to output the svg for each term in a taxonomy loop. When it comes to that, ACF requires the term variable to be passed on as a second parameter in get_field()
.
So I tried this:
<?php $svgImg = get_field('my_custom_field', $term, 'option'); ?>
<?php echo file_get_contents( $svgImg ); ?>
But I get this php error:
“Warning: “file_get_contents() expects parameter 1 to be a valid path”
Seems like it´s not an issue related to the order of the parameters as when I swap $term
and option
, it makes WP blind to what term I´m referring to:
“Warning: file_get_contents(): Filename cannot be empty”
$term
has been properly defined as I have tested it with:
<?php $svgImg = get_field('my_custom_field', $term); ?>
<img src="<?php echo $svgImg['url']? />">
This last piece of code works. But the previous doesn´t.
Can somebody help?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.