sorry for the multiple responses. Sending problem...
Okay this is interesting, but I do not think it is directly related to Toolset. I set up a test in my local test environment and had similar results with various shortcodes, even with custom shortcodes unrelated to Toolset. Somewhere, either in Elementor or WordPress, there is built-in logic that prevents execution of shortcodes inside a script tag's src attribute. This could be a security feature, or a bug in Elementor or WordPress, or something else I don't know about. You can try this test to confirm my findings. I placed this code in a Text Editor element, in the "Text" tab (not "Visual" tab):
<script type="text/javascript">[wpv-post-url]</script>
<script type="text/javascript" src="[wpv-post-url]"></script>
<script type="text/javascript">[my-custom-shortcode][/my-custom-shortcode]</script>
<script type="text/javascript" src="[my-custom-shortcode][/my-custom-shortcode]"></script>
The wpv-post-url shortcode is built-in to Toolset Blocks/Views, but my-custom-shortcode has nothing to do with Toolset. It is a custom shortcode created with custom code. It just returns a simple URL string for testing purposes:
add_shortcode( 'my-custom-shortcode', 'my_custom_shortcode');
function my_custom_shortcode($atts)
{
return "<em><u>hidden link</u></em>";
}
The results in the page markup are similar to what you have experienced - the shortcodes in script tag src attributes are not executed, even though the same shortcodes work correctly when nested inside the script tags:
<script type="text/javascript"><em><u>hidden link</u></em>;
<script type="text/javascript" src="[wpv-post-url]"></script>
<script type="text/javascript"><em><u>hidden link</u></em>;
<script type="text/javascript" src="[my-custom-shortcode][/my-custom-shortcode]"></script>
Screenshots attached here. The problem occurs with shortcodes completely unrelated to Toolset, and even when Toolset plugins are completely disabled. Shortcodes simply are not executed inside script tag src attributes in this scenario, regardless of whether or not Toolset plugins are involved. I think you may need a custom shortcode that returns the complete script tag with dynamic src attribute as needed, or a custom field that stores the entire dynamic script tag.
I try with this code, but always the same result. Did I make a mistake in the code?
function shortcode_Procure(){
$ean = "[types field='ean' output='raw'][/types]";
return '<script type="text/javascript" id="script_widget_notice" src="<em><u>hidden link</u></em>' . $ean . '&color=1&largeur=100%&id_affilie_widget=478"></script>' ;
}
add_shortcode('LaProcure', 'shortcode_Procure');
Did I make a mistake in the code?
Well I think placing the shortcode in the src URL just repeats the same problem.
$ean = "[types field='ean' output='raw'][/types]";
return '<script type="text/javascript" id="script_widget_notice" src="<em><u>hidden link</u></em>' . $ean . '&color=1&largeur=100%&id_affilie_widget=478"></script>' ;
The result here is the Types field shortcode placed directly in the src URL like this:
<script type="text/javascript" id="script_widget_notice" src="<em><u>hidden link</u></em> field='ean' output='raw'][/types]&color=1&largeur=100%&id_affilie_widget=478"></script>
That is basically the same problem we have already experienced. Shortcodes do not work in this src attribute. You don't want the shortcode in the src URL, you want to evaluate the shortcode and place the value of the field in the URL. Something like this:
<script type="text/javascript" id="script_widget_notice" src="<em><u>hidden link</u></em>"></script>
The preferred way to get the value of a custom field in PHP is to use the Types Field API types_render_field. Something like this:
$ean = types_render_field("ean", array("output" => "raw"));
https://toolset.com/documentation/customizing-sites-using-php/functions/#numeric
Then the $ean variable will contain the value of the custom field, not the shortcode. Does this make sense?
Yes, it works! It's perfect!
Thank you very much for your help!