Allow users to add custom functions to wordpress theme

My suggestion would be to use get_template_part. I think that is the closest you can get to what you want.

You may be able to just drop get_template_part('userfuncts'); into your functions.php. That will load userfuncts.php from your theme’s main directory, if the file is present, or from a child theme’s directory if applicable. See the Codex for how the function searches for files. It is a stepped-up version of PHP’s include really. Any function that would work in functions.php should work in that included file. But that is an important condition. Some things do not load well from a theme’s functions.php and need to be in a plugin.

However, EAMann has a good point. While it is possible to update the theme without losing the userfuncts.php file, that is not necessarily the case. It is fairly common to completely delete a theme and then upload the update. I don’t know how the automatic updater does this, as I never use that updater, but if it deletes and then reinstalls you are going to have trouble.

You could do something like create two directories for your theme– the main one and a second user functions directory.

  • wp-content/themes/my-theme
  • wp-content/themes/my-theme-userfuncts

Then create a get_template_part-like function to load files from that directory. It shouldn’t be hard to do using get_template_part as a model. You’d have a kind of pseudo-child theme. It could be a source of confusion but good docs would help a lot and I have no idea how ‘proper’ that solution is. I only just thought about it. Hope I don’t get yelled at 🙂

Your theme could just install itself and a child but the you’d have the same update issue if you ever altered the child.