How to load parent_theme functions.php before child_theme?

Justin Tadlock recently wrote a great post about making a better functions.php file
where (if I remember correctly) he deals with this exact issue.

Unfortunately his site is down at the moment so I have to rely on my memory for now.

You are on the right track with the after_setup_theme hook.

  1. As far as I remember the trick is to wrap your filters and actions into it’s function.
    See example below.
  2. You do that in both parent and child functions.php files.
  3. Then you can play with the priority of these two hooks.

Little bit of code worth thousand words – your parent theme’s function.php should look like this:

add_action( 'after_setup_theme', 'your_parent_theme_setup', 9 );
function your_parent_theme_setup() {    
    add_action(admin_init, your_admin_init);
    add_filter(the_content, your_content_filter);
}

function your_admin_init () {
...
}

function your_content_filter() {
...
}

Leave a Comment