如何在 Blogus 主题页脚添加备案号
网上没有很清晰的添加备案号的方法,这里就来填个坑吧~
第一步:找到页脚文件的路径
Blogus 主题的页脚内容是通过一个名为 hook-footer-section.php
的 hook 文件进行管理的,这个文件的路径是:
/wp-content/themes/blogus/inc/ansar/hooks/hook-footer-section.php
找到文件后,我们可以使用文本编辑器(例如 VS Code、Notepad++ 等)或者 WordPress 自带的在线编辑器打开文件进行编辑。
第二步:修改页脚内容,添加粤ICP备12345678号-1
在打开的 hook-footer-section.php
文件中,找到如下代码片段,这部分代码是用来生成页脚中的版权声明的:
if( ! function_exists( 'blogus_footer_copyright' ) ) :
function blogus_footer_copyright() {
hide_copyright = esc_attr(get_theme_mod('hide_copyright',true));blogus_footer_copyright = get_theme_mod( 'blogus_footer_copyright','Copyright © All rights reserved' );
if (hide_copyright == true ) { ?>
<div class="bs-footer-copyright">
<div class="container">
<div class="row">
<?php if ( has_nav_menu( 'footer' ) ) { ?>
<div class="col-md-6 text-left text-xs">
<p class="mb-0">
<span class="copyright-text">
<?php echo esc_html(blogus_footer_copyright); ?>
</span>
<span class="sep"> | </span>
<?php printf(esc_html__('%1s by %2s.', 'blogus'), '<a href="https://themeansar.com/free-themes/blogus/" target="_blank">Blogus</a>', '<a href="https://themeansar.com" target="_blank">Themeansar</a>'); ?>
</p>
</div>
<?php } ?>
</div>
</div>
</div>
<?php }
}
endif;
add_action( 'blogus_footer_copyright_content', 'blogus_footer_copyright' );
这段代码的作用是生成页脚中的版权信息,如“Blogus by Themeansar.”等内容。接下来,我们需要在这部分代码的相应位置添加粤ICP备12345678号-1的 HTML 代码。
修改代码
在版权信息代码的后面添加如下粤ICP备12345678号-1代码:
<span class="sep"> | </span>
<a href="https://beian.miit.gov.cn" target="_blank" style="text-decoration:none;">
粤ICP备12345678号-1
</a>
这样做的目的是将粤ICP备12345678号-1显示在页脚中,确保符合国内网站的合规要求。以下是完整修改后的代码片段:
if( ! function_exists( 'blogus_footer_copyright' ) ) :
function blogus_footer_copyright() {
hide_copyright = esc_attr(get_theme_mod('hide_copyright',true));blogus_footer_copyright = get_theme_mod( 'blogus_footer_copyright','Copyright © All rights reserved' );
if (hide_copyright == true ) { ?>
<div class="bs-footer-copyright">
<div class="container">
<div class="row">
<?php if ( has_nav_menu( 'footer' ) ) { ?>
<div class="col-md-6 text-left text-xs">
<p class="mb-0">
<span class="copyright-text">
<?php echo esc_html(blogus_footer_copyright); ?>
</span>
<span class="sep"> | </span>
<?php
printf(esc_html__('%1s by %2s.', 'blogus'),
'<a href="https://themeansar.com/free-themes/blogus/" target="_blank">Blogus</a>',
'<a href="https://themeansar.com" target="_blank">Themeansar</a>');
?>
<span class="sep"> | </span>
<a href="https://beian.miit.gov.cn" target="_blank" style="text-decoration:none;">
粤ICP备12345678号-1
</a>
</p>
</div>
<?php } ?>
</div>
</div>
</div>
<?php }
}
endif;
add_action( 'blogus_footer_copyright_content', 'blogus_footer_copyright' );
第三步:保存并刷新页面
完成修改后,保存 hook-footer-section.php
文件。然后刷新你的网站,滚动到页脚部分,检查粤ICP备12345678号-1是否正确显示。如果操作无误,页脚部分应显示如下信息:
Copyright © All rights reserved | Blogus by Themeansar. | 粤ICP备12345678号-1
总结
通过以上简单的几步操作,我们成功地在 Blogus 主题的页脚中添加了备案号。希望这个教程对你有所帮助,如果在操作过程中遇到任何问题,可以评论向我寻求帮助。