[wp-hackers] What goes in a theme and what goes in a plugin

Nikola Nikolov nikolov.tmw at gmail.com
Thu Jan 23 19:34:44 UTC 2014


When I started working in web development, the work process of the company
I worked at was to put all of the code for a specific website in it's
theme. That means post types, custom fields, theme option interfaces,
shortcodes, etc.

I was recently introduced to the idea that this is definitely not a good
way of creating websites, simply because when the client decides to freshen
up the design of their website, they would either have to rewrite the
templates of the theme, or painfully extract all of the vital parts of the
code out of the theme(or create a child theme, but the themes we were
making were not really meant for using as parent themes).

Instead you should try to leave only the styling to the theme and have
everything else in one(or multiple?) plugins.

I agree with that idea, but my biggest question is how much do you put in
the plugin and how much you leave in the theme. For instance if you want to
display some custom data in the theme(in places different than with
the_content()), but still have templates(so that appearance can be tweaked
from the theme) - do you define some of the functions in the theme, do you
just rely on the plugin being active.

Let me give you an example. You have custom fields(maybe the plugin you
created for the theme is creating them, or it's a third plugin that does
that). You want to display the information from those fields in the theme
and you want to make them easy to access, so you have a function that
returns an array with all of the data. Do I create a function in the theme,
that would pull the data(possibly relying on the plugin by using
function_exists() to prevent fatal errors), do I just use the plugin's
function in the theme?

I would appreciate personal experience, as well as references to articles
on the topic(or a link to a message on the list if it's been discussed
before).

Thanks,
Nikola


More information about the wp-hackers mailing list