目前我正在与包含多个辅助功能文件的functions.php的Wordpress主题工作。如果儿童主题是基于主题制作的,我希望这个主题非常灵活和可定制。包括从儿童主题根目录或包括从父主题根目录
我有这样一段代码目前在我的functions.php:
add_action('template_redirect', 'wpf_contact');
/**
* Include the logic/settings for tpl-contact.php.
*
* Includes the logic/settings for tpl-contact.php. It will load the child's
* mail.inc.php first if that is available.
*/
if (! function_exists('wpf_contact')) {
function wpf_contact() {
if (is_page_template('tpl-contact.php') && is_child_theme() && file_exists(get_stylesheet_directory() . '/inc/wpf/mail.inc.php')) {
include(get_stylesheet_directory() . '/inc/wpf/mail.inc.php');
} else {
include(get_template_directory() . '/inc/wpf/mail.inc.php');
}
} // end wpf_contact()
}
什么上面的代码确实是从子载荷mail.inc.php如果存在的文件。如果它不从父主题加载它。
原因我有多个文件想加载。我在想,这可能不是一个更简单的方法吗?有没有一个内置函数在WordPress中做到这一点?
或者我应该只是调整上述函数并添加参数,以便它可以用于其他文件?不知道这是否有效。
此问题属于[wordpress.se]。 – brasofilo
Tnx,我已经为它加书签! – Ilyes512