分类
编程

如何在WordPress添加尾部备案信息

WordPress版本:5.4.1中文版

一、准备

1.请确认你的插件中有优化(会修改wordpress的运行代码的)功能的插件是禁用的,以免修改文件无效

2.打开终端,连接你的服务器,准备修改wp-config.php文件,以及重新创建zh_CN.php文件

二、开始添加

因为该文件缺失,导致就算完成了第二步也不能实现要求

1).打开终端,切换到wordpress/wp-content/language目录

2).新建zh_CN.php文件,并向其中添加以下内容

<?php
/**
 * ICP license number
 *
 * For compliance with the Telecommunications Regulations. Can be turned off
 * in wp-config.php.
 *
 * @since 3.7.0
 */
function zh_cn_l10n_settings_init() {
    if ( defined( 'WP_ZH_CN_ICP_NUM' ) && WP_ZH_CN_ICP_NUM ) {
        add_settings_field( 'zh_cn_l10n_icp_num',
            'ICP备案号',
            'zh_cn_l10n_icp_num_callback',
            'general' );
        register_setting( 'general', 'zh_cn_l10n_icp_num' );
    }
}

add_action( 'admin_init', 'zh_cn_l10n_settings_init' );

function zh_cn_l10n_icp_num_callback() {
    echo '<input name="zh_cn_l10n_icp_num" type="text" ' .
        'id="zh_cn_l10n_icp_num" value="' .
        esc_attr( get_option( 'zh_cn_l10n_icp_num' ) ) .
        '" class="regluar-text ltr" />' .
        '<p class="description">仅对WordPress自带主题有效。</p>';
}

function zh_cn_l10n_icp_num( $content ) {
    if ( defined( 'WP_ZH_CN_ICP_NUM' ) && WP_ZH_CN_ICP_NUM &&
            get_option( 'zh_cn_l10n_icp_num' ) ) {
        echo '<a href="http://www.miitbeian.gov.cn/" rel="nofollow" ' .
            'title="工业和信息化部ICP/IP地址/域名信息备案管理系统">' .
            esc_attr( get_option( 'zh_cn_l10n_icp_num' ) ) .
             "</a>\n";
    }
}

add_action( 'twentyten_credits', 'zh_cn_l10n_icp_num' );
add_action( 'twentyeleven_credits', 'zh_cn_l10n_icp_num' );
add_action( 'twentytwelve_credits', 'zh_cn_l10n_icp_num' );
add_action( 'twentythirteen_credits', 'zh_cn_l10n_icp_num' );
add_action( 'twentyfourteen_credits', 'zh_cn_l10n_icp_num' );
add_action( 'twentyfifteen_credits', 'zh_cn_l10n_icp_num' );
?>

2.修改wp-config.php文件
1).切换到wordpress的根目录

2).修改wp-config.php文件,向其中添加以下内容

define('WP_ZH_CN_ICP_NUM', true);

目的是开启wordpress显示icp备案的功能

3.修改主题文件中的footer文件
1).进入wordpress后台中的外观选项卡,主题编辑器标签页,在右边选择你使用的主题,同时在下方找到footer.php,在其中合适的位置(见图)添加以下内容

<a href="http://www.beian.miit.gov.cn" rel="external nofollow" target="_blank">
       <?php echo get_option( 'zh_cn_l10n_icp_num' );?>
</a>

4.正常修改备案号设置
在wordpress后台设置选项卡,常规标签页中的备案号设置中设置备案号

到此结束!

转载自:https://blog.awolon.fun/2019/12/350/