找到网站个目录下文件夹:wp-include文件夹下的class-wp.php,定位此代码段(V3.6在144行)

老高温馨提示:使用本教程前请备份数据库及相关文件

if ( isset($_SERVER['PATH_INFO']) )
    $pathinfo = $_SERVER['PATH_INFO'];
else
    $pathinfo = '';
$pathinfo_array = explode('?', $pathinfo);
$pathinfo = str_replace("%", "%25", $pathinfo_array[0]);
$req_uri = $_SERVER['REQUEST_URI'];

修改为 

if ( isset($_SERVER['PATH_INFO']) )
    $pathinfo = mb_convert_encoding($_SERVER['PATH_INFO'], "UTF-8", "GBK");
else
    $pathinfo = '';
$pathinfo_array = explode('?', $pathinfo);
$pathinfo = str_replace("%", "%25", $pathinfo_array[0]);
$req_uri = mb_convert_encoding($_SERVER['REQUEST_URI'], "UTF-8", "GBK");

至此,wordpress已经学会读中文了。

还有一种解决方式,即给每一个标签都设置一个英文别名,这样设置的标签还是不能使用中文,可以使用下面的代码将所有的标签格式化:

<?php
    header("Content-type: text/html; charset=utf-8");
    // 修改:LAOGAO https://blog.phpgao.com/
    define('MYSQL_HOSTNAME', 'localhost');
    define('MYSQL_USERNAME', 'yourusername');
    define('MYSQL_PASSWORD', 'yourpassword');
    define('MYSQL_DATABASE', 'yourdatabase');
    define('MYSQL_TABLEPRE', 'wp_'); // 表前缀

    error_reporting(E_ALL);
    ini_set('display_errors', 'On');

    $link = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD);
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully<br />';

    mysql_select_db(MYSQL_DATABASE, $link);

    // 下面三句的作用是设置当前连接编码为UTF-8标准。
    // 所以请确保你的WordPress数据库是符合UTF-8编码标准,
    // 否则请自行将下面的UTF-8改成相应的字符集。
    mysql_set_charset('utf8', $link);
    mysql_query('SET NAMES UTF8');
    mysql_query("SET character_set_results = 'utf8', " . "character_set_client = 'utf8', " . "character_set_connection = 'utf8', " . "character_set_database = 'utf8', " . "character_set_server = 'utf8'", $link);
    // 字符设置结束
    echo '<br />';

    // 下面为encode编码tag中的中文slug
    $res = mysql_query("SELECT `term_id`,`name` FROM " . MYSQL_TABLEPRE . "terms");
    //echo "SELECT `term_id`,`slug` FROM ".MYSQL_TABLEPRE."terms";
    while ($row = mysql_fetch_array($res)) {
        echo 'id=' . $row[0] . ' - ' . 'name=' . $row[1] . ' --- ';
        if (mysql_query('UPDATE `' . MYSQL_TABLEPRE . 'terms` SET `slug`=\'' . urlencode($row[1]) . '\' WHERE `term_id` =' . $row[0])) {
            echo 'UPDATED!<br />';
        }
    }
    // 编码结束

    mysql_close($link);

    echo '完成!<br />';
    exit();
?>