这篇帖子上有很多无用的评论,这似乎是一个很简单的问题。
更改如下$theme_directory_name = \'twentyfourteen\';
到您的主题。。。这就是你所要做的。第一个函数可以设置主题。第二个选项禁用编辑主题的界面。
function selfish_hardcoded_theme() {
$theme_directory_name = \'twentyfourteen\';
add_filter( \'template\', create_function( \'$template\', \'return "\' . $theme_directory_name . \'";\' ) );
add_filter( \'stylesheet\', create_function( \'$stylesheet\', \'return "\' . $theme_directory_name . \'";\' ) );
}
add_action( \'setup_theme\', \'selfish_hardcoded_theme\', -1 );
add_filter( \'map_meta_cap\', function( $required_caps, $cap ) {
if ( \'edit_themes\' == $cap || \'switch_themes\' == $cap || \'install_themes\' == $cap || \'delete_themes\' == $cap || \'update_themes\' == $cap ) {
$required_caps[] = \'do_not_allow\';
}
return $required_caps;
}, 10, 2 );
还有其他方法:
$theme = wp_get_theme();
if (\'twentyfourteen\' !== $theme->name || \'twentyfourteen\' !== $theme->parent_theme) {
switch_theme( \'twentyfourteen\' );
}
您还可以在wp配置中设置默认主题常量。
最后,从管理中删除主题菜单:
function remove_themes_submenus() {
global $submenu;
unset($submenu[\'themes.php\'][5]); // Removes \'Themes\'
unset($submenu[\'themes.php\'][15]); // Removes Theme Installer tab
}
add_action(\'admin_menu\', \'remove_themes_submenus\');