RESOLVED Is it possible to Run Snippet inside img src?

arminvit

New member
Messages
3
Likes
0
Points
1
#1
Hi,

I have a snippet that contains the path to my image folder on my server:

Code:
<?php $url = site_url( '/', 'https' );echo $url; ?>
If I use the snippet on its own it does work but when I try to use it like below, it doesn't work — the img src outputs the snippet itself. How can I use a snippet in img src?

Code:
<img src="[wbcr_php_snippet id="187" title="Image Path"]images/abc.jpg" alt="abc" />
Thank you.
 

Temyk

Developer & Support
Messages
1,129
Likes
42
Points
48
#2
Hello.

In the next plugin update, you can enable processing of shortcodes in snippets in the settings.
In the meantime you can do it like this:
PHP:
<img src="<?php echo do_shortcode('[wbcr_php_snippet id="187"]');?>images/abc.jpg" alt="abc" />
 

arminvit

New member
Messages
3
Likes
0
Points
1
#3
Hello.

In the next plugin update, you can enable processing of shortcodes in snippets in the settings.
In the meantime you can do it like this:
PHP:
<img src="<?php echo do_shortcode('[wbcr_php_snippet id="187"]');?>images/abc.jpg" alt="abc" />
Thanks for the reply Temyk. I forgot to mention that the snippet is placed inside a post so it won't run php code (which is why I wanted to use WS in the first place!). I used to use [insertphp] in an older website I have and I could run that old plugin but that's not the best practice.
 

Temyk

Developer & Support
Messages
1,129
Likes
42
Points
48
#4
In this case, everything should work. I tried it on my site and it worked. Try this
PHP:
<img src="[wbcr_php_snippet id='187']images/abc.jpg" alt="abc" />
 

arminvit

New member
Messages
3
Likes
0
Points
1
#5
In this case, everything should work. I tried it on my site and it worked. Try this
PHP:
<img src="[wbcr_php_snippet id='187']images/abc.jpg" alt="abc" />
Ugh — I'm embarrassed! You are right, it does work. I just realized my mistake: I forgot to upload the file in the directory I was referencing. Sorry!