我刚刚下载了主题来查看它,还有标题扩展。php未作为模板加载:
/** Load Structure */
require_once (AMBITION_STRUCTURE_DIR . \'/header-extensions.php\');
因此,您无法以这种方式重写文件。我不确定您到底想做什么,但看起来野心\\u headercontent\\u details方法位于名为野心\\u header的挂钩中,因此您可以删除他们的操作,并在任何需要的地方添加自己的内容。这是在孩子主题的功能中实现的一种方法。php:
<?php
/**
* Remove the Ambition parent theme headercontent_details filter.
* @see https://developer.wordpress.org/reference/functions/remove_action/
*/
add_action( \'init\', \'ambition_child_remove_action\');
function ambition_child_remove_action() {
remove_action( \'ambition_header\', \'ambition_headercontent_details\', 10 );
}
/**
* Add child theme override for ambition_headercontent_details.
* @see https://developer.wordpress.org/reference/functions/add_action/
*/
add_action( \'ambition_header\', \'ambition_child_headercontent_details\' );
/**
* Shows Header content details
*
* Shows the site logo, title, description, searchbar, social icons and many more
*/
function ambition_child_headercontent_details() { ?>
<?php global $ambition_settings;
$header_image = get_header_image();
if (!empty($header_image)):?>
<a href="<?php echo esc_url(home_url(\'/\'));?>"><img src="<?php echo esc_url($header_image);?>" class="header-image" width="<?php echo get_custom_header()->width;?>" height="<?php echo get_custom_header()->height;?>" alt="<?php echo esc_attr(get_bloginfo(\'name\', \'display\'));?>">
</a>
<?php
endif;?>
<div class="hgroup-wrap">
<div class="container clearfix">
<?php
$ambition_settings = wp_parse_args( get_option( \'ambition_theme_settings\', array() ), ambition_get_option_defaults() );
$header_display = $ambition_settings[\'header_settings\'];
$header_logo = $ambition_settings[\'img-upload-header-logo\'];
if ($header_display != \'disable_both\' && $header_display == \'header_text\') { ?>
<section id="site-logo" class="clearfix">
<?php if(is_single() || (!is_page_template(\'page-templates/page-template-business.php\' )) && !is_home()){ ?>
<h2 id="site-title">
<a href="<?php echo esc_url(home_url(\'/\'));?>" title="<?php echo esc_attr(get_bloginfo(\'name\', \'display\'));?>" rel="home">
<?php bloginfo(\'name\');?>
</a>
</h2><!-- #site-title -->
<?php } else { ?>
<h1 id="site-title">
<a href="<?php echo esc_url(home_url(\'/\'));?>" title="<?php echo esc_attr(get_bloginfo(\'name\', \'display\'));?>" rel="home">
<?php bloginfo(\'name\');?>
</a>
</h1><!-- #site-title -->
<?php }
$site_description = get_bloginfo( \'description\', \'display\' );
if($site_description){?>
<h2 id="site-description"> <?php bloginfo(\'description\');?> </h2>
<?php } ?>
</section><!-- #site-logo -->
<?php
} elseif ($header_display != \'disable_both\' && $header_display == \'header_logo\') {
?>
<section id="site-logo" class="clearfix">
<?php if(is_single() || (!is_page_template(\'page-templates/page-template-business.php\' )) && !is_home()){ ?>
<h2 id="site-title">
<a href="<?php echo esc_url(home_url(\'/\'));?>" title="<?php echo esc_attr(get_bloginfo(\'name\', \'display\'));?>" rel="home"> <img src="<?php echo $header_logo;?>" alt="<?php echo esc_attr(get_bloginfo(\'name\', \'display\'));?>"></a>
</h2>
<?php }else{ ?>
<h1 id="site-title">
<a href="<?php echo esc_url(home_url(\'/\'));?>" title="<?php echo esc_attr(get_bloginfo(\'name\', \'display\'));?>" rel="home"> <img src="<?php echo $header_logo;?>" alt="<?php echo esc_attr(get_bloginfo(\'name\', \'display\'));?>"></a>
</h1>
<?php } ?>
</section><!-- #site-logo -->
<?php }?>
<button class="menu-toggle"><?php _e(\'Responsive Menu\', \'ambition\' ); ?></button>
<?php
if (has_nav_menu(\'primary\')) {// if there is nav menu then content displayed from nav menu else from pages ?>
<section class="hgroup-right">
<?php $args = array(
\'theme_location\' => \'primary\',
\'container\' => \'\',
\'items_wrap\' => \'<ul class="nav-menu">%3$s</ul>\',
); ?>
<nav id="site-navigation" class="main-navigation clearfix" role="navigation">
<?php wp_nav_menu($args);//extract the content from apperance-> nav menu ?>
</nav><!-- #access -->
<?php } else {// extract the content from page menu only ?>
<section class="hgroup-right">
<nav id="site-navigation" class="main-navigation clearfix" role="navigation">
<?php wp_page_menu(array(\'menu_class\' => \'nav-menu\')); ?>
</nav><!-- #access -->
<?php }
$search_form = $ambition_settings[\'search_header_settings\'];
if (1 != $search_form) { ?>
<div class="search-toggle"></div><!-- .search-toggle -->
<div id="search-box" class="hide">
<?php get_search_form();?>
<span class="arrow"></span>
</div><!-- #search-box -->
<?php } ?>
</section><!-- .hgroup-right -->
</div><!-- .container -->
</div><!-- .hgroup-wrap -->
<?php global $disable_slider;
global $ambition_settings;
if (is_front_page()) {
$disable_slider = $ambition_settings[\'disable_slider\'];
if (empty($disable_slider)) {
if (function_exists(\'ambition_pass_slider_effect_cycle_parameters\')) {
ambition_pass_slider_effect_cycle_parameters();
}
if (function_exists(\'ambition_featured_sliders\')) {
ambition_featured_sliders();
}
}
} else {
if ((\'\' != ambition_header_title()) || function_exists(\'bcn_display_list\')) {
$sitetitle_img_setting = $ambition_settings[\'site_title_setting\'];
$sitetitle_image = $ambition_settings[\'img-upload-site-title\']; ?>
<div class="page-title-wrap" <?php if ( $sitetitle_img_setting != \'1\' && $sitetitle_image != \'\' ){ ?> style="background-image:url(\'<?php echo esc_url($sitetitle_image);?>\');" <?php } ?> >
<div class="container clearfix">
<?php if(is_home()){?>
<h2 class="page-title"><?php echo ambition_header_title();?></h2><!-- .page-title -->
<?php } else { ?>
<h1 class="page-title"><?php echo ambition_header_title();?></h1><!-- .page-title -->
<?php }
if (function_exists(\'ambition_breadcrumb\')) {
ambition_breadcrumb();
}
?>
</div><!-- .container -->
</div><!-- .page-title-wrap -->
<?php
}
}
}
如果您试图在标题之后输出图像,并且不需要修改实际的标题,那么您只需要在子主题的函数中使用类似于此的方法以稍后的优先级连接。php文件:
<?php
/**
* Add Banner to the ambition_header hook.
*/
add_action( \'ambition_header\', \'ambition_child_add_banner\', 15 );
function ambition_child_add_banner() {
?>
<img id="single-program-banner" src="<?php the_field( \'banner\' ); ?>" alt="" />
<?php
}
另外,我不知道您对该方法的使用情况,但您可能希望确保它与以下内容一起安全使用
https://developer.wordpress.org/reference/functions/esc_url/编辑:我把这些文件放在了一个要点中,如果需要,可以进行测试:https://gist.github.com/timelsass/754aa14b367b3f54b16d44ae13b540a7