我正在使用Twententen作为我的基础创建一个孩子主题。我正在寻找一种删除添加自定义标头和背景的功能而无需触摸的方法 functions.php 在父主题中文件。

没有运气:(

function my_child_theme_setup() {
    remove_theme_support('custom-background');
    remove_theme_support('custom-header');
}

add_action( 'after_setup_theme', 'my_child_theme_setup' );
有帮助吗?

解决方案

标题和背景图像功能都设置了一些全球范围的工作,以使这些全球群体摆脱了一定的效果,并且至少将它们从管理方面删除。

add_action('after_setup_theme', 'remove_theme_features', 11 );

function remove_theme_features() {
    $GLOBALS['custom_background']   = 'kill_theme_features';
    $GLOBALS['custom_image_header'] = 'kill_theme_features';
}
class kill_theme_features {
    function init() { return false; }
}

期望提供一个类名称作为这两个功能的回调,并且都期望给定的类具有初始化方法。解决方案是创建一个无用并更新全球的虚拟类别,该类别有效地杀死了管理区域中的主题背景和标题页。

希望有帮助。

其他提示

孩子主题是在父母主题之前处理的。因此,您的功能正在较早上吸引,并在之前开火 twentyten_setup().

尝试:

add_action( 'after_setup_theme', 'my_child_theme_setup', 11 );

或者您可以复制 twentyten_setup() 以您的孩子为主题并修改,因为有条件地声明 ! function_exists( 'twentyten_setup' )

remove_theme_support 应该做到这一点。

编辑-

似乎自定义标题和自定义背景具有自己的功能: 自定义标题 。我认为相同类型的函数应该适用于自定义背景,但是在引用中找不到它,在文件中搜索它。

编辑2-

remove_custom_image_header 根据法典,功能仅适用于3.1。我现在建议Rarst的建议。

尝试:

function my_child_theme_setup() {
    global $_wp_theme_features;
    unset( $_wp_theme_features['custom-background'] );
    unset( $_wp_theme_features['custom-header'] );

}

add_action( 'after_setup_theme', 'my_child_theme_setup' );

希望这可以帮助

从简短的搜索到核心,我无法验证 remove_custom_image_header() *). 。我只找到 add_custom_image_header() 使用 add_theme_support(), ,所以这应该起作用。

如果不这样做,您可以靠近核心并使用 主题修改API. 。奇怪的是:API仅具有删除所有修改的函数: remove_theme_mods() 这没有其他参数。

考虑到它,您最好的机会是过滤它: add_filter( "theme_mod_$name", 'your_callback_fn' );, ,但是我不确定它是否从管理UI中删除了它(它确实有10%的机会)。因此,也许您必须通过另一个功能来删除该菜单条目。

无论如何:看看 ~/wp-includes/theme.php ...这是“二十个”核心支持文件(我猜其他主题不会使用)。

*)这真的很奇怪...

编辑:

remove_custom_image_header() 现在可以使用WP 3.1+使用。

@t310s的简短编辑答案:

function remove_theme_features() 
{
    $GLOBALS['custom_background']   = '__return_false';
    $GLOBALS['custom_image_header'] = '__return_false';
}
add_action( 'after_setup_theme', 'remove_theme_features', 20 );

只是 .

许可以下: CC-BY-SA归因
scroll top