In the parent theme, the following is at the bottom of the functions.php file.

require_once(TEMPLATEPATH . '/admin/admin-menu.php');

In the child theme's function.php, this code will include the child admin panel.

require_once(STYLESHEETPATH . '/admin/admin-menu.php');

As you can see, I shouldn't use both files b/c the bottom file includes get_stylesheet_directory_uri() instead of get_template_directory_uri() for certain localized files (js, css). Thus, I need to remove the parent file from loading

I believe I need to use the remove_action hook, but I'm not sure how to do this right. Can't find a good answer on Google either.

I started writing the following in the functions.php file in my child theme, but I don't know how to write it properly.

function remove_parent_admin_panel {
   remove_action('remove_panel', '[WHAT-GOES-HERE?]');
}

Then I guess I need to use a add_action hook to add the above function to remove the parent admin panel.

Should I wrap the parent require_once with a function statement? Am I on the right track?

link|improve this question

67% accept rate
feedback

2 Answers

up vote 3 down vote accepted

For cases where you want to require/include PHP files, but still allow child themes to replace those PHP files outright, then you should use the locate_template function.

Example: Parent does this:

locate_template( 'admin/file.php', true );

This finds the admin/file.php file in either the child or the parent theme, then does a require on it (that's what the true is for).

So to replace the file in the child, you just replace the file in the child. Simple. Easy.

Note: The method defaults to using require_once. If you just want to require only, then pass a third parameter of false.

link|improve this answer
Interesting, that's good to know. So, what you're saying is that, in both child and parent functions.php files, I should include the code you wrote above? – micah Jul 7 '11 at 18:27
No, in the child theme you don't have to include anything but the modified file. The parent will make the locate_template call, and that call will automatically load the admin/file.php from the child instead of the parent, if the child has such a file. This is the basis for child theme file replacements, the parent makes the call, and the child can then replace specific files without any special coding at all. – Otto Jul 7 '11 at 18:28
Wow, that's awesome. In all the reading I did about child themes, I never saw this but it's very useful and seems to work correctly for me. Thanks! – micah Jul 7 '11 at 18:35
feedback

Inside of the Parent Theme's \admin\admin-menu.php file, look for the function add_menu_page(). It should be wrapped in a function, and that function called in an add_action( 'admin_init', 'function-name' ) call.

You need to call remove_action( 'admin_init', 'function-name' ) for whatever that function name is.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.