简体   繁体   English

隐藏Wordpress父主题

[英]Hiding Wordpress parent theme

I am using the child theme and have renamed it to the new theme name. 我正在使用子主题并将其重命名为新的主题名称。 However, the parent theme is still viewable in the admin area with the original theme name. 但是,父主题仍可以在管理区域中以原始主题名称查看。 How do I hide the parent theme? 如何隐藏父主题? Thanks. 谢谢。

As far as I know this cannot be done. 据我所知这是无法完成的。 The idea behind child themes is to be Update Safe. 子主题背后的想法是“更新安全”。

This means, you can update the parent theme and all the child theme functionality goes unaffected. 这意味着,您可以更新父主题,而所有子主题功能均不受影响。 If you want to hide the parent theme, you are better off forking it. 如果要隐藏父主题,最好将其分叉。

As i seen on wp-admin/themes.php file that wordpress use function called wp_prepare_attachment_for_js to collect the available theme information and then display it on themes page. 正如我在wp-admin/themes.php文件中看到的wp-admin/themes.php ,wordpress使用名为wp_prepare_attachment_for_js函数来收集可用的主题信息,然后将其显示在主题页面上。

The function wp_prepare_attachment_for_js located on wp-admin/theme.php may be line 409 and seems the function have filter wp_prepare_attachment_for_js , so i think this will be done with this filter by unset the selected theme (parent theme to hide) before displayed to the available themes. 位于wp-admin/theme.php上的函数wp_prepare_attachment_for_js可能是第409行,似乎该函数具有过滤器wp_prepare_attachment_for_js ,因此我认为将通过在未显示为可用之前取消设置所选主题(隐藏父主题)来使用此过滤器完成此操作主题。

try add filter like this to your functions.php 尝试将类似的过滤器添加到您的functions.php

add_filter( 'wp_prepare_themes_for_js', 'test_hide_themes', 11, 1 );
function test_hide_themes($prepared_themes){

    // hide parent-theme theme
    unset($prepared_themes['your-parent-theme-slug']);

    return $prepared_themes;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM