I need to make a PHP variable that takes get_template_directory_uri()
, appends /assets/images
and appends the_sub_field('icon')
and appends the string -colored.png
how do I do this?
The correct output needs to looks like this:
...assets/images/icon-linkedin-colored.png
...assets/images/icon-facebook-colored.png
I've confirmed the output of <div><?php echo the_sub_field('icon') ?></div>
is correct.
The first thing I tried:
<?php $iconName = echo get_template_directory_uri() + '/assets/images/' + the_sub_field('icon') + '-colored.png'; ?>
In VS code I just get "No quick fixes available which doesn't help me.
PHP - concatenate or directly insert variables in string
I then tried
<?php $iconName = get_template_directory_uri() . '/assets/images/' . the_sub_field('icon') . '-colored.png'; ?>
Because I forgot you do .
for trying strings (or string concactenation)
But the output of this is
.../assets/images/-colored.png
Why is it JUST giving -colored.png
? What is wrong with my string operation?
It needs to be .../assets/images/icon-linkedin-colored.png