我想删除由二十七岁主题自动添加在标题部分的
custom-header
部分。
我知道我可以做到以下几点:
.custom-header{
display: none;
}
但我不想通过CSS删除它。我想通过 functions.php 删除它。
我搜索了二十十七代码,我发现文件中
/wp-content/themes/twentyseventeen/inc/custom-header.php
包含由add_action
函数自定义的标头部分。
功能如下:
add_action( 'after_setup_theme', 'twentyseventeen_custom_header_setup' );
所以我在我的二十七儿童主题的functions.php文件中添加了以下函数:
function remove_custom_header() {
remove_action('after_setup_theme', 'twentyseventeen_custom_header_setup');
}
add_action('after_setup_theme', 'remove_custom_header');
但它仍然出现。
我正在使用 WP-Optimize 插件来缓存文件,但我已经清除了文件并预加载了文件,但它仍然出现。我猜测,如果通过 add_action 添加自定义标头,我可以使用 remove_action 来避免被包含。
我应该如何通过functions.php删除自定义标头部分?
提前致谢!
好吧,我终于明白发生了什么了。有两部分代码似乎加载了《二十七岁》主题的
custom-header
部分。
一是我在问题中描述的代码,但这不是对我产生影响的代码部分。如果您想覆盖它,复制我添加到问题中的
remove_custom_header
函数就足够了。
进一步观察,我发现 header.php 文件中有一行正在加载
custom-header
部分。我正在谈论的线路如下:
get_template_part( 'template-parts/header/header', 'image' );
正在加载文件
/wp-content/themes/twentyseventeen/template-parts/header/header-image.php
,其中包含 custom-header
HTML 代码。我已将 header.php 文件复制到我的子主题并删除了该行。 custom-header
部分已被删除。