Passer la navigation

[Résolu] Add code using custom field

This support ticket is created Il y a 2 years, 5 months. 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Fuseau horaire du supporter : Asia/Kolkata (GMT+05:30)

Ce sujet contient 3 réponses, a 2 voix.

Dernière mise à jour par Minesh Il y a 2 years, 5 months.

Assisté par: Minesh.

Auteur
Publications
#2678439

SD

Is there any way to add code(for example analytics/tracking code) to a custom post type using a custom field?

For example, give the ability to the user to add an analytics code and have it injected in the post/template if the field is filled. So that it only tracks the specific post.

#2678447

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Maybe its a good idea to add a custom field that holds the status like "Show analytics", you can add checkbox or select field with yes and no options and then with the content template you should add a conditional block or shortcode to display that said JS code based on the selected option. Does that makes sense?

More info:
- https://toolset.com/course-lesson/using-toolset-conditional-block/

#2678449

SD

Hi there, it does make sense but i was wondering if there is a way so the user would be able to add different tracking code per post on the go.

#2678453

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

I do not see any way as sooner or later it may create issues as it will be JS code you will be trying to save inside database.

Logically or theoretically it should work.

You may want to use the following sandbox site and create a multiline text custom field and try to save the data per post and check if its working as expected.

You can auto-login to the sandbox site using the following link:
- lien caché