0

I have functions for setting default values when a new user signs up, functions for performance testing, functions for writing out a small icon to the admin tool bar, and so on.

These functions are scattered around where I'm using them, which is in templates, plugins, and so on. Where should I be putting them? I know there is a theme/functions.php and a wp-includes/functions.php and that seems like the logical place to put them, but my hosting company is set to upgrade my installs to the latest versions. I don't want my code in the functions.php to be overwritten. What should I do?

2

wp-includes/functions.php is never a file you should modify. Any mention of adding something to functions.php is never referring to this file.

Functions related to front-end display or theme behavior should go in your theme's functions.php. If the theme may potentially be updated, then you should be using a Child Theme to add functionality, and they should go in your child theme's functions.php. Child themes are update-safe - a core update will not overwrite a child theme.

For any code that should persist regardless of active theme, those functions should go in your own plugin. Your own plugins are update-safe.

Regardless of what option you choose, you should always have a local recent backup in case you need to restore things.

|improve this answer|||||
  • OK. It sounds like I should create a plugin then. I have a few event handlers for "wpmu_new_blog". Can I put those in the plugin? – 1.21 gigawatts Nov 13 '15 at 21:49
  • 1
    yes, those would be most appropriate in a plugin. – Milo Nov 13 '15 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.