Tag Info

Hot answers tagged

4

At the risk of getting voted down by everybody else here who thinks this is OK. I say: No, you shouldn't define functions in template files. This should be considered bad practice. Let's have a look at the documentation: Functions File Explained. The functions file behaves like a WordPress Plugin, adding features and functionality to a WordPress ...


2

Sure. If your function is really just doing some control switching, putting it into the template is fine. Anything more than that traditionally goes into functions.php or similar. Edit: +10 at Pieter Goosen's mention of trying to keep things DRY. It can actually be difficult to keep things DRY with WordPress theming. I'm a fan of the Sage starter theme. ...


1

There is no wrong or right way, neither is there any type of set rule or standard stating where custom code should go or not. This is all personal preference. There are few guidelines which you should use (if you want to) Templates (and all code for that matter) should be kept organised, maintainable, and easy to read and understand. Do not clot code ...



Only top voted, non community-wiki answers of a minimum length are eligible