How do I remove a require_once admin panel from the parent theme from the child theme functions.php?

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.

Leave a Comment