Codeinwp/flat

Allow Theme Functions to be Overriden

Closed this issue · 2 comments

If the custom functions employed by the theme were wrapped in a function_exists conditional, it would allow child theme authors to easily replace theme functions with custom ones, rather than copying every template file that makes use of the function into the child theme so that the function call can be pointed to the new child theme function.

What functions do you think its can be override? I have saw on some default theme, some functions can't be override on the child theme.

Any function, really. Child themes can change anything about a parent theme, provided the parent theme is coded to be flexible. If every function that Flat defines is wrapped, a child theme can use their own version of it.

For example, if flat_widgets_init() is wrapped in a function_exists() conditional, then a child theme can substitute its own widget handling for Flat's default.

The function I was wanting to easily replace was flat_entry_meta(). If that function was wrapped, then in my child theme, I could have simply defined a new flat_entry_meta() that would have been used instead of Flat's default. However, because there was no way to override Flat's default, I had to copy each template file (such as content.php) to my child theme, change the function call to something like private_entry_meta() and create a function by that name in my functions file. This is less than ideal because when Flat updates, my template files may not reflect the latest structure updates and results in more that'll need checked.

Further reading: http://www.fklein.info/function_exists-in-a-theme/