Should I create a theme or a plugin?

Try to keep the business logic out of the theme. Dealing with images is always an edge case, because they do affect presentation, which is usually a theme job.

But the logic of how to get and order these images, the JavaScript parts and the backend are probably better in a separate code base. That is also easier for version control, because you can focus on one problem that is complex enough already.
I would just add a custom action to the theme, maybe like this:

do_action( 'content_before' );

See ticket #21506 for a discussion of standard theme hooks.

Your plugin could then insert its content with:

add_action( 'content_before', 'your_plugin_callback' );

Provide a separate stylesheet, but offer an option for themes to override that per add_theme_support().

And the best thing is: you can reuse the code in the next project if you keep it flexible enough. Or share it on wordpress.org. Or sell it.

See also: Where to put my code: plugin or functions.php?

Leave a Comment