There has been some discussion in recent weeks about the use of functions.php in the theme folder as oppose to using a plugin instead and the golden rule, in my opinion, is that anything that is not directly related to your WordPress theme should be in a plugin. Here I will outlined how I approach the issue.
Themes these days in WordPress mean you can do practically anything. In fact anything a plugin can do which means running any PHP code you want. However themes are interchangeable, and therefore if you include code in theme when the theme is not active that code will not run.
Therefore my advice, and this is something that I do with every WordPress project that I completed is to create a ‘utility’ plugin with each site. In this plugin is all the non theme related code for the site. Examples of the things I include in these plugins are as follows:
- Custom post types
- Custom taxonomies
- Dashboard modifications
By including these in a plugin rather than a theme means a theme change in the future will not break that functionality of leave you with no custom post types.
WordPress Cumbria is a monthly WordPress meet up that takes place in Kendal, Cumbria. The October meet up was the second meet up between WordPress Developers, Designers, Users and anyone interested in the publishing platform. I was invited to speak at this months event.
My short talk was entitled Extensible WordPress plugins and offered information about what an extensible plugin is, how you can make plugin extensible that you are writing as well as examples of how to take advantage of plugin extensibility. View the slides below:
Photo credit: https://twitter.com/tnash/status/522349421347209216
Have you every had a time when you have added two of the same widget to a sidebar and wanted to style them differently? You may have run into problems as they have the same CSS classes etc. and the ID they are given is random. This is why I created the Simple Widget Classes WordPress plugin.
The plugin simply adds an additional text input box to each widget added to a sidebar in the admin. In here you can type the names of any classes (space separated) that you would like to give to the widget. This can then be used for custom styling.
Download this really simple plugin from wordpress.org.