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?
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.
Inside of the Parent Theme’s
adminadmin-menu.php
file, look for the functionadd_menu_page()
. It should be wrapped in a function, and that function called in anadd_action( 'admin_init', 'function-name' )
call.You need to call
remove_action( 'admin_init', 'function-name' )
for whatever that function name is.