Skip Navigation

[Resolved] Dynamic script tag src URL parameter set by custom numeric field

This thread is resolved. Here is a description of the problem and solution.

Problem: I need to add a script tag to my Custom Template. In the script tag's src attribute, I would like to append a URL variable and value coming from a custom field, but I cannot get the Types numeric field shortcode to work correctly. The shortcode is written out in the src URL instead of being executed. I need to add the custom field's numeric value in a URL parameter attached to the src URL.

Solution: It turns out that WordPress does not execute shortcodes in script tags URL parameters, whether or not Toolset is involved.Thi p The same problem can be seen even if custom shortcodes are use i . The solution in this case is to get the value of the custom field using the types_render_field API, then append that value to the src attribute URL using a custom shortcode.

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/functions/#numeric

This support ticket is created 4 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 19 replies, has 2 voices.

Last updated by vincentR-2 4 years ago.

Assisted by: Christian Cox.

Author
Posts
#2095853
capture-ean.png

Tell us what you are trying to do?

Is there any documentationHello,
I use Toolset with Elementor Pro.
I use toolset to manage a publication type "Book". Among the fields of this publication type, its EAN number.

This site is affiliated with an online bookstore to sell the books listed. The line of code for the affiliation is of the type :
<script type="text/javascript" id="script_widget_notice" src="hidden link"></script>

So to generate this line automatically, I need to include the EAN reference in the line of code. But I can't do it.

I edit a text block in Elementor, I can display the EAN field value using [types field='ean' output='normal' format='FIELD_VALUE'][/types]

but when I use <script type="text/javascript" id="script_widget_notice" src="hidden link field='ean' output='normal' format='FIELD_VALUE'][/types]&color=1&width=195&id_affiliate_widget=xxx"></script>
It doesn't work. The value of the EAN field is not integrated.

Example page: hidden link
I don't know how to do it anymore. Thank you in advance for your help.

Thank you in advance for your help,
Vincent

Translated with hidden link (free version) that you are following?

Is there a similar example that we can see?

What is the link to your site?

#2096155

Hello, I suggest you try output='raw' in your Types field shortcode, and remove the format attribute to prevent problems with formatting:

<script type="text/javascript" id="script_widget_notice" src="<em><u>hidden link</u></em> field='ean' output='raw'][/types]&color=1&width=195&id_affiliate_widget=xxx"></script>

If this does not work as expected, something else must be going on. I may need to take a closer look.

#2096189

Hello, thank you for your reply. Unfortunately... no change...

#2096765
Screen Shot 2021-06-23 at 9.21.30 AM.png

It looks like the Types field shortcode is not being evaluated, it is simply written out into the content of the page. See the screenshot here, you can see the shortcode is not executed in the script tag. Can you explain how you inserted the script tag into the page here? Is it included in an Elementor builder template somehow? What type of "block" or "element" did you use to insert this content? Please provide a screenshot or screenshots showing the script tag code in the template or page builder, and let me know which blocks or element is used to insert this content.

#2096791
capture-ean-bloc-editor.png

Yes, that's exactly the problem.

I tried several ways, they all give the same result. Either the code is not interpreted, or no data is sent, while above the same line returns the data...

I don't understand...

Here is the capture of what I have actually put.

But I also tried :
[wpv-autop]<script type="text/javascript" id="script_widget_notice" src="hidden link field='ean' output='raw'][/types]&color=1&width=100%&id_affiliate_widget=478"></script>[/wpv-autop]

and

<script type="text/javascript" id="script_widget_notice" src="hidden link field='ean' output='raw'][/types]&color=1&width=100%&id_affiliate_widget=478"></script>

It's the same...

Incomprehensible to me.

#2096803
capture-ean-bloc-editor.png

Yes, that's exactly the problem.

I tried several ways, they all give the same result. Either the code is not interpreted, or no data is sent, while above the same line returns the data...

I don't understand...

Here is the capture of what I have actually put.

But I also tried :
[wpv-autop]<script type="text/javascript" id="script_widget_notice" src="hidden link field='ean' output='raw'][/types]&color=1&width=100%&id_affiliate_widget=478"></script>[/wpv-autop]

and

<script type="text/javascript" id="script_widget_notice" src="hidden link field='ean' output='raw'][/types]&color=1&width=100%&id_affiliate_widget=478"></script>

It's the same...

It's incomprehensible to me...

#2096813
capture-ean-bloc-editor.png

Yes, that's exactly the problem.

I tried several ways, they all give the same result. Either the code is not interpreted, or no data is sent, while above the same line returns the data...

I don't understand...

Here is the capture of what I have actually put.

But I also tried :

[wpv-autop]<script type="text/javascript" id="script_widget_notice" src="<em><u>hidden link</u></em> field='ean' output='raw'][/types]&color=1&width=100%&id_affiliate_widget=478"></script>[/wpv-autop]

and

<script type="text/javascript" id="script_widget_notice" src="<em><u>hidden link</u></em> field='ean' output='raw'][/types]&color=1&width=100%&id_affiliate_widget=478"></script>

It's the same...

It's incomprehensible to me...

#2096823
capture-ean-bloc-editor.png

Yes, that's exactly the problem.

I tried several ways, they all give the same result. Either the code is not interpreted, or no data is sent, while above the same line returns the data...

I don't understand...

Here is the capture of what I have actually put.

But I also tried :

[wpv-autop]<script type="text/javascript" id="script_widget_notice" src="<em><u>hidden link</u></em> field='ean' output='raw'][/types]&color=1&width=100%&id_affiliate_widget=478"></script>[/wpv-autop]

and

<script type="text/javascript" id="script_widget_notice" src="<em><u>hidden link</u></em> field='ean' output='raw'][/types]&color=1&width=100%&id_affiliate_widget=478"></script>

It's the same...

It's incomprehensible to me...

#2096833
capture-ean-bloc-editor.png

Yes, that's exactly the problem.

I tried several ways, they all give the same result. Either the code is not interpreted, or no data is sent, while above the same line returns the data...

I don't understand...

Here is the capture of what I have actually put.

But I also tried with [wpv-autop][/wpv-autop] and without anything

It's the same...

It's incomprehensible to me...

#2096843

Yes, that's exactly the problem.

I tried several ways, they all give the same result. Either the code is not interpreted, or no data is sent, while above the same line returns the data...

I don't understand...

Here is the capture of what I have actually put.

But I also tried with wpv-autop and without anything

It's the same...

It's incomprehensible to me...

#2096845
capture-ean-bloc-editor.png

Yes, that's exactly the problem.

#2096857

impossible to answer

#2096861
capture-ean-bloc-editor.png

Yes, that's exactly the problem.

I tried several ways, they all give the same result. Either the code is not interpreted, or no data is sent, while above the same line returns the data...

I don't understand...

Here is the capture of what I have actually put in a text bloc (in text mode, not visual mode).

But I also tried :
[wpv-autop]<script type="text/javascript" id="script_widget_notice" src="hidden link field='ean' output='raw'][/types]&color=1&width=100%&id_affiliate_widget=478"></script>[/wpv-autop]

and

<script type="text/javascript" id="script_widget_notice" src="hidden link field='ean' output='raw'][/types]&color=1&width=100%&id_affiliate_widget=478"></script>

It's the same...

It's incomprehensible to me...

#2096871
capture-ean-bloc-editor.png

Yes, that's exactly the problem.

I tried several ways, they all give the same result. Either the code is not interpreted, or no data is sent, while above the same line returns the data...

I don't understand...

Here is the capture of what I have actually put in a text bloc (in text mode, not visual mode).

But I also tried :
[wpv-autop]<script type="text/javascript" id="script_widget_notice" src="hidden link field='ean' output='raw'][/types]&color=1&width=100%&id_affiliate_widget=478"></script>[/wpv-autop]

and

<script type="text/javascript" id="script_widget_notice" src="hidden link field='ean' output='raw'][/types]&color=1&width=100%&id_affiliate_widget=478"></script>

It's the same...

It's incomprehensible to me...

#2096881
capture-ean-bloc-editor.png

Yes, that's exactly the problem.

I tried several ways, they all give the same result. Either the code is not interpreted, or no data is sent, while above the same line returns the data...

I don't understand...

Here is the capture of what I have actually put in a text bloc (in text mode, not visual mode).

But I also tried :
[wpv-autop]<script type="text/javascript" id="script_widget_notice" src="hidden link field='ean' output='raw'][/types]&color=1&width=100%&id_affiliate_widget=478"></script>[/wpv-autop]

and

<script type="text/javascript" id="script_widget_notice" src="hidden link field='ean' output='raw'][/types]&color=1&width=100%&id_affiliate_widget=478"></script>

It's the same...

It's incomprehensible to me...