[wp-hackers] Organizing my theme's functions.php file

Micky Hulse mickyhulse.lists at gmail.com
Thu Aug 15 23:42:09 UTC 2013


Howdy,

Here's a "pseudo 10,000 ft. view" of my `functions.php` file:

<https://gist.github.com/mhulse/6245870#file-1-pseudo-functions-before-php>

Long story short, I'm in the process of setting up a child theme for a
co-worker and I decided it was time to do some house cleaning and make
my parent theme's functions/hooks/other easier for child themes to
override.

I found this awesome article out on the net:

"WordPress theme function files"
<http://justintadlock.com/archives/2010/12/30/wordpress-theme-function-files>

Excellent tips!

With that said, I do have some questions:

1. For all custom functions that aren't tied into a WP hook, should I
wrap them with `if ( ! function_exists('some_custom_function')) {
some_custom_function() { ... } }` (as opposed to wrapping all
functions in a `function_exists` call)?

2. Based on Justin's excellent article above, I'm under the impression
that I should move all of my `add_action()`'s, `remove_action()`'s,
`add_filter()`'s, `remove_filter()`'s (and similar) into the
`foo_setup` function (which is hooked into `after_setup_theme`)? In
other words, should my functions.php file look more like this:

<https://gist.github.com/mhulse/6245870#file-2-pseudo-functions-after-php>

I have to admit, that "pseudo 10,000 ft. view" does look much cleaner
and organized.

I just wanted to ask the pros before I go making sweeping changes to
my theme's function.php.

Let me know if I need to clarify my questions better.

Many thanks in advance!

Cheers,
M


More information about the wp-hackers mailing list