php - 如何在 Wordpress 中覆盖父模板的页脚?
问题描述
我是 Wordpress 和 PHP 的新手,我尝试了一些东西来尝试覆盖我的页脚,但我找不到方法。我的情况是父母的页脚不可配置,我不知道如何在孩子中覆盖它。
家长代码
footer.php (我要修改的部分在get_template_part( 'template-parts/footer/site', 'info' );)
<?php
/**
* The template for displaying the footer
*
* Contains the closing of the #content div and all content after
*/
?>
</div><!-- .wrapper -->
</div><!-- .site-content -->
<?php get_template_part( 'template-parts/footer/footer', 'instagram' ); ?>
<footer id="colophon" class="site-footer" role="contentinfo">
<?php get_template_part( 'template-parts/footer/footer', 'widgets' ); ?>
<div id="site-generator">
<?php get_template_part( 'template-parts/navigation/navigation', 'footer' ); ?>
<?php get_template_part( 'template-parts/footer/site', 'info' ); ?>
</div><!-- #site-generator -->
</footer><!-- .site-footer -->
</div><!-- .site -->
<?php wp_footer(); ?>
</body>
</html>
网站信息.php
<?php
/**
* The template used for displaying credits
*
*/
?>
<?php
/**
* credits hook
* @hooked footer_content - 10
*/
do_action( 'credits' );
模板标签.php
<!-- More code before -->
/**
* Footer Text
*
* @get footer text from theme options and display them accordingly
* @display footer_text
* @action footer_content
*
*/
function footer_content() {
$theme_data = wp_get_theme();
$default_footer_content = sprintf( _x( 'Copyright © %1$s %2$s. All Rights Reserved. %3$s ', '1: Year, 2: Site Title with home URL, 3: Privacy Policy Link', 'parent-theme' ), esc_html( date_i18n( __( 'Y', 'parent-theme' ) ) ), '<a href="'. esc_url( home_url( '/' ) ) .'">'. esc_html( get_bloginfo( 'name', 'display' ) ) . '</a>', get_the_privacy_policy_link() . $theme_data->get( 'Name' ) . ' ' . esc_html__( 'by', 'parent-theme' ) . ' <a target="_blank" href="' . esc_url( $theme_data->get( 'AuthorURI' ) ) . '">' . esc_html( $theme_data->get( 'Author' ) ) . '</a>' );
$footer_content = '
<div class="site-info">
<div class="wrapper">';
$footer_content .= '<div id="footer-left-content" class="copyright">' . $default_footer_content . '</div>';
$footer_content .= '
</div><!-- .wrapper -->
</div><!-- .site-info -->';
echo $footer_content;
}
add_action( 'credits', 'footer_content', 10 );
<!-- More code after-->
所以这个footer_content()函数是我想要覆盖的函数。在我的子主题的functions.php中,我尝试在添加以下内容后取消挂钩'footer_content'挂钩以添加我的:
孩子的密码
/**
* Footer (overrided)
*/
function remove_parent_footer_function() {
remove_action('after_setup_theme', 'footer_content');
}
add_action('wp_loaded', 'remove_parent_footer_function');
function child_footer_content() {
$theme_data = wp_get_theme();
$default_footer_content = sprintf( _x( 'Copyright © %1$s %2$s. All Rights Reserved. %3$s ', '1: Year, 2: Site Title with home URL, 3: Privacy Policy Link', 'parent-theme' ), esc_html( date_i18n( __( 'Y', 'parent-theme' ) ) ), '<a href="'. esc_url( home_url( '/' ) ) .'">'. esc_html( get_bloginfo( 'name', 'display' ) ) . '</a>', get_the_privacy_policy_link() . '' );
$footer_content = '
<div class="site-info">
<div class="wrapper">';
$footer_content .= '<div id="footer-left-content" class="copyright">' . $default_footer_content . '</div>';
$footer_content .= '
</div><!-- .wrapper -->
</div><!-- .site-info -->';
echo $footer_content;
}
add_action('after_setup_theme', 'child_footer_content');
但结果是“child_footer_content()”被执行,在网站顶部创建了一个包含正确信息的 div,但父页脚没有被修改并继续显示在底部。
知道我做错了什么吗?
解决方案
推荐阅读
- pandas - pandas:按 ffill 分组不适用填写正确的顺序
- rust - Rust 是否具有与 Python 的字典理解语法等价的功能?
- xcode - 使用未解析的标识符“FirebaseApp”:已经存在的解决方案都没有工作
- python - 格式化多个python变量
- google-chrome-extension - 为什么我的 chrome 扩展程序的徽标和宣传图片是像素化的?
- python - sympy atan 没有返回确切的值
- python - Pytorch,通过第一个和最后一个元素扩展张量的有效方法
- javascript - WebRTC 数据通道不会发送?
- reactjs - 使用 AWS Cognito 用户池、联合身份提供商和 AWS Amplify
- python - TypeError:找不到所需的参数“mat”(位置 2)