How to organize WordPress functions

So for most WordPress users this may sound familiar.

You make an active child-theme and a functions.php. After a while this php file will be filled with many action/filter hooks. Some for WordPress itself, others for plugins. This makes it (to me) a hot mess. It’s hard to keep an overview what’s going on without making big blocks of comments.

Read More

How can one best approach this? I was considering turning the large functions.php into:

  • multiple plugins
  • multiple php files which are included within the functions.php.

What would be the best practice and give the best performance?

Related posts

Leave a Reply

2 comments

  1. make an inc directory within your WordPress child theme’s root and add categorized function files within that. Then include them in your functions.php file:

    - js
    - css
    - inc
      general.php
      cpt_first.php
      cpt_second.php
      navigation.php
    - ...
    functions.php
    
  2. Best approach is to write plugin’s function in there in plugin’s function file and the same for the theme. If you are gonna add any new feature in theme let say custom post type and taxonomies and you can’t handle that code in function.php file then develop a plugin for custom post type and you can manage all custom post type code within that plugin.
    Hope it helps 🙂