Skip Navigation

[Resolved] Add code using custom field

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 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 1 year ago.

Assisted by: Minesh.

Author
Posts
#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

Languages: English (English )

Timezone: 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

Languages: English (English )

Timezone: 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:
- hidden link