WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer
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 '12 at 18:36
See my update, I use locate_template() to make the life of child theme authors easier. – toscho Oct 11 '12 at 18:41
This is great, thanks for the advice! – AlxVallejo Oct 11 '12 at 18:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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