Best practice: put code in functions.php or template file?

Community Forums Forums General Discussion Best practice: put code in functions.php or template file?

This topic is: not resolved

This topic contains 2 replies, has 2 voices, and was last updated by  lucaslem 1 year, 6 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #107072


    Given that functionality and styling often overlap, a lot of code can be placed either in functions.php or in a separate template file (ex: cpt-single.php in the case of a custom post type). Is there a best practice which dictates when one should create a template and when one can just stick the code in functions file?



    Depends. For templates most will go in the template but once there its not as flexible as if its in the functions file.

    Good question but also fairly broad as well.

    I have found WordPress Developers ( Stackexchange ) a good place to post code and ask for feedback as long as its specific to WordPress and not plugins or themes.



    Thanks Brad, will definitely check out stackxchange for specific code issues.

    I was asking mainly because I read somewhere that it’s not a good idea to have a very large functions file, though it was never made clear why nor was specified how many lines actually make the file “large”. I find it easier to put my code in functions (even for structural HTML changes) just because I can easily apply that code to (or remove it from) other sections of the site with a quick conditional change.

    I will create templates if they make life easier for clients.

    Good to know the answer is indeed “it depends” and not some hard and fast rule. Cheers.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.