Moving functionality from functions.php to classes?

This code https://github.com/chriscoyier/css-tricks-functionality-plugin does exactly what you’ve described with regard to classes. Although the associated article https://css-tricks.com/wordpress-functionality-plugins/ is about removing non-theme specific functionality out of functions.php to a separate plugin it will give you an insight into the code.

HOWEVER:

PHP includes do have a performance overhead. I have also read (older versions of PHP) that classes add a performance overhead, although I beleive this is not the case with PHP 7.

I am unsure whether you are i. modifying a theme for use on your site, or ii.developing a new Theme.

If just for your site. I improve maintainability and reduce the size of my child functions.php by limiting it to theme specific functions only; other site functionality is contained in a separate plugin as explained in article above (but just the one file not lots of classes and includes). This file is also very large; but I’ve also commented in an index at the start and prominent section headings and do not have a problem maintaining it.

If you are developing and publishing new theme: bear in mind many users who are happy to use/modify functions do not have the same confidence with object oriented stuff and it may put them off using/childing your theme. Additionally, if they’re like me, I find it much easier and less irritating to refer to one large properly commented and sectioned file than have to use functions.php as a look up index to see what other files I need then go away and open to copy, edit or extend.

Leave a Comment