Straight to the question: It seems that there are only so many places to place custom code: functions.php, plugin, template, shortcode. Having too many plugins slows down your load times, inflating the functions.php file can get unmanageable, same with a template, and shortcodes really depend on the situation.

I have a homepage with a lot of custom code and queries on it: Latest comments, most popular content, most liked content, featured content, custom slider of featured content, newest posts, etc.

This makes for a cluttered homepage when I'm trying to make edits to the code.

I've used shortcodes for a lot of the queries but I'm still left with a cluttered page. My plugins is maxed out (39 active) and my functions is quite full as well. I am packing a lot of custom code into my site but I'm curious as to what your thoughts on the best way to organize all of your custom functions. How do you choose between placing your code into functions.php vs making it a plugin? Are there ways of extending functions.php so that you don't have to run-up your plugin count and you can better organize your custom functions?

1 Answer 1


Organize your code by its purpose: If it creates output on the front end and requires changes in your theme's style sheet - it belongs to the theme. You don't have to put everything into the functions.php, split he code into several files if it helps.
For example like this:

// extra functions just for nav menus
locate_template( 'php/functions.nav-menu.php', TRUE, TRUE );

If it should survive a theme switch (Custom post types, shortcodes) or is not related to the theme at all - it belongs to a plugin.

The pure number of plugins is irrelevant: 200 fast plugins are better than one slow plugin.

Template files are for views - they should not contain function definitions that are hard to find there. And shortcodes are a special API, not places.

  • So to split code in functions.php, would you use require_once(extra_functions.php)? Also in regards to template files, in my case, I'm using a custom homepage so wouldn't it make sense to put my homepage functions on the homepage template if they won't be used anywhere else? (These are query functions)
    – AlxVallejo
    Oct 11, 2012 at 18:36
  • See my update, I use locate_template() to make the life of child theme authors easier.
    – fuxia
    Oct 11, 2012 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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