RESOLVED Snippet not processed when inside script URL source attribute?

Status
Not open for further replies.

NCF

New member
Messages
2
Likes
0
Points
1
#1
Here's the markup of my page:

Code:
<div id="appContainer">Loading, please wait&#8230;</div>
<script type="text/javascript" src="//[wbcr_php_snippet id='8161'].cristinanetwork.org/includes/js/mloader.ncf?linkid=11"></script>
And the PHP code for that snippet:

Code:
if (preg_match("/dev\./i",$_SERVER['HTTP_HOST'])) { echo "proto"; } else { echo "www"; }
So you can see it just detects whether the code is being called in a development environment (based on the subdomain) and outputs an appropriate subdomain for the src attribute of the JavaScript block.

Why does the snippet not get processed in this scenario? If I pull it outside the src="" it gets processed fine.

Help is appreciated...

-b
 

Kirill

Support team
Messages
82
Likes
4
Points
8
#2
Hello

It looks like WordPress prevents injection in script tag.
I suggest a workaround:

HTML:
[wbcr_php_snippet id='8161']

<script type="text/javascript" src="//%s.cristinanetwork.org/includes/js/mloader.ncf?linkid=11"></script>

[/wbcr_php_snippet]
Snippet:
PHP:
if (preg_match("/dev\./i",$_SERVER['HTTP_HOST'])) { $subdomain =  "proto"; } else { $subdomain =  "www"; }

echo sprintf($content, $subdomain);

Note. $content variable contains text between shortcode tags.


Best regards
 

NCF

New member
Messages
2
Likes
0
Points
1
#3
That worked great, thank you for the quick and effective technical support. I did not realize that snippets/shortcodes worked quite like that. Very informative...

-b
 
Status
Not open for further replies.