Skip Navigation

[Resolved] Custom Code Snippets or Functions file

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

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)

Tagged: 

This topic contains 8 replies, has 2 voices.

Last updated by Ben 5 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1175351

Ben

Is it best to add custom code using Toolset's Custom Code Snippets option or by inserting the code into the Functions.php file? Are there any differences between these two methods? Pros and cons etc?

#1175382

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Yes - I suggest you should use the Toolset's Custom Code Snippets and all benefits listed here with the following link:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/#benefits-of-adding-custom-code-using-toolset

#1176978

Ben

Minesh, according to that link, using Custom Code Snippets opens up a potential security issue. Does the same issue exist when using a functions.php file?

#1177443

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - to fix that security issue, we already mentioned how you can fix that security issue so no direct access is allowed:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/#security

To protect each custom code file , we have following check.

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

I recommend you to use Toolset's Custom Code Snippets option as if you add custom code to functions.php file, lets say if you update the theme, there is the possibility that you may lose the data.

#1177659

Ben

Thank you for the information and help so far Minesh.

How would I go about "converting" all my custom code from a functions.php file to Custom Code Snippets? Is it as simple as just copying it all across and pasting the above security check code at the top?

#1177663

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

How would I go about "converting" all my custom code from a functions.php file to Custom Code Snippets? Is it as simple as just copying it all across and pasting the above security check code at the top?
==> Yes, you should just copy/paste it to custom code snippets BUT after the security check code line. Dont forget to activate it.

#1177675

Ben
Screenshot 2019-01-04 at 14.08.11.png

Can you confirm from the attached screenshot that I have done this correctly?

#1178934

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - thats the place just after the security line you should place your code. Looks OK to me.

#1183621

Ben

Thank you Minesh.