Skip Navigation

[Resolved] Need to place widget javascript code in a field in the post editor & display FE

This support ticket is created 3 years, 3 months 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 5 replies, has 3 voices.

Last updated by kevinS-30 3 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#2151381

Hi guys and thanks in advance for helping

I would like to be able to use some code available from a website: this generates a CQC rating and link to the ratings page.

This code would be unique to each post - and I would like to copy the post into the post editor - then pull this into a dynamic toolest block in the template so it generates the button and link

The widget is here:

each centre has its own unique code for the cqc rating

hidden link

The code looks like this ( the id changes for each centre )

<script type="text/javascript" src="//www.cqc.org.uk/sites/all/modules/custom/cqc_widget/widget.js?data-id=1-4658761602&data-host=www.cqc.org.uk&type=location"></script>

At the moment I have an html block ( non toolset ) on the template with 1 of the codes pasted in so I can see what it looks like - but essentially I need to make that are dynamic, ideally with a toolset custom field on the back end of the toolset post editor - which then pulls the code into position on the page..

the result of the static code in the html block can be seen here

hidden link

That is the result I would like to achieve .. but with code entry dynamic on the back end editor

Hope you can help ..

Many thanks .

Kevin Scott

#2151475

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Kevin

The id is stored as a field on each post, so that it can be output with a shortcode?

If that's the case you should be able to dynamically generate the id part of the above, like so:

<script type="text/javascript" src="//www.cqc.org.uk/sites/all/modules/custom/cqc_widget/widget.js?data-id=[wpv-post-field name="my-id-field"]&data-host=www.cqc.org.uk&type=location"></script>

If it is a Types custom field then you would need to prefix the slug with wpcf-, e.g. "wpcf-my-id-field".

I think shortcodes are parsed in a Custom HTML block, you should be able to add the code there, otherwise you may need to use a Classic block.

#2151513

Hi there

Oddly your reply isnt shown here - nor can I find my support ticket listed so have had to copy from my email the reply was

Dear Kevin,

Nigel from Toolset support has added the following message to your support thread:

Need to place widget javascript code in a field in the post editor & display FE
Hi Kevin

The id is stored as a field on each post, so that it can be output with a shortcode?

If that's the case you should be able to dynamically generate the id part of the above, like so:

If it is a Types custom field then you would need to prefix the slug with wpcf-, e.g. "wpcf-my-id-field".

I think shortcodes are parsed in a Custom HTML block, you should be able to add the code there, otherwise you may need to use a Classic block.

In your reply There is a gap after 'like so with nothing in it !! which im guessing is the critical bit : but perhaps I was unclear

I want to

1) Have a field in my post that the user can copy paste the entire Javascipt code into each post ( code copied from CQC site)

2) Render this code on the front end using the centres template I have created - meaning the CQC rating will be unique to each post

the example of what it should look like is here : hidden link

I just want to be able to put the short code for each centre in the back end and render it on the front end

maybe thats the stuff thats missing in the email ?

#2151893

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kevin,

This was Nigel's response to your query.


Hi Kevin

The id is stored as a field on each post, so that it can be output with a shortcode?

If that's the case you should be able to dynamically generate the id part of the above, like so:

<script type="text/javascript" src="//www.cqc.org.uk/sites/all/modules/custom/cqc_widget/widget.js?data-id=[wpv-post-field name="my-id-field"]&data-host=www.cqc.org.uk&type=location"></script>

If it is a Types custom field then you would need to prefix the slug with wpcf-, e.g. "wpcf-my-id-field".

I think shortcodes are parsed in a Custom HTML block, you should be able to add the code there, otherwise you may need to use a Classic block.

Thanks,
Shane

#2152603

HI Guys

I couldn't get the code working using a dynamic Id within the code

I did resolve and find a workaround...

1) Created a new custom field ( text )
2) Place the whole of the code script in the field
3) Used a single field block in the template
4) Used the post source to pull in the correct field - which generated a short code and displays the widget

see

hidden link

#2152605

Found a work around. My issue is resolved now. Thank you!