我将这段代码添加到函数文件中,因此根据插件是否被激活有不同的主题选项。
function theme_options_select() {
if( is_plugin_active( 'gallery-nails/gallery-nails.php' )) {
require get_template_directory() . '/inc/theme-options/nails/theme-options.php';
}
else {
require get_template_directory() . '/inc/theme-options/default/theme-options.php';
}
}
add_action( 'wp_loaded', 'theme_options_select' );我尝试过plugin_loaded和setup_theme,但是主题选项是不可访问的。init同样有效,但也破坏了登录。
有人知道怎么解决这个问题吗?
发布于 2017-11-05 12:55:23
如果这是在functions.php中,那么您根本不需要挂钩,因为functions.php文件是装在你想要的地方。因此,只需打开它并将它完全从函数调用中移出;也就是说,仍然在您的functions.php中,但不附加到任何特定的钩子上。
或者,如果您想稍微延迟它,可以使用after_setup_theme挂钩。
https://wordpress.stackexchange.com/questions/285023
复制相似问题