关于 Blog 修改

本 Blog 使用的是 WordPress,每次升级 WordPress 都需要修改文件,以修正一些问题,因此做个总记录,便于自己修改。

解决 WordPress 无法打开中文链接的文章(服务器支持 UTF-8,不再需要修改文件支持中文链接。)

wp-includes/class-wp.php 153 行:

$pathinfo = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] : '';

修改为:

$pathinfo = isset( $_SERVER['PATH_INFO'] ) ? mb_convert_encoding($_SERVER['PATH_INFO'], 'utf-8', 'GBK') : '';

wp-includes/class-wp.php 157 行:

list( $req_uri ) = explode( '?', $_SERVER['REQUEST_URI'] );

修改为:

list( $req_uri ) = explode( '?', mb_convert_encoding($_SERVER['REQUEST_URI'], 'utf-8', 'GBK') );

解决 WordPress 自动把半角符号替换为全角符号

两种解决方案:(采取第二种解决方案,WordPress 升级不需要再次修改。)

第一种:(修改 Blog 程序文件)

wp-includes/formatting.php 138 行与 140 行:

$curl = str_replace($static_characters, $static_replacements, $curl);
// regular expressions
$curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);

修改为:

// $curl = str_replace($static_characters, $static_replacements, $curl);
// regular expressions
// $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);

第二种:(修改主题中的 functions.php)

打开 functions.php 文件添加以下语句:

/* 禁止文章标题自动全半角转换 */
remove_filter('the_title', 'wptexturize');
/* 禁止文章内容自动全半角转换 */
remove_filter('the_content', 'wptexturize');

解决 WordPress 评论 aria-required='true',造成无法通过 W3C 验证

将 wp-includes/comment-template.php 所有 aria-required='true' 删除,1975 行:

$aria_req = ( $req ? " aria-required='true'" : '' );

修改为:

$aria_req = ( $req ? " " : '' );

wp-includes/comment-template.php,1998 行:

'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',

修改为:

'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" ></textarea></p>',

解决 baidu-sitemap 插件在发布或修改文章出现 PHP Warning

关于 baidu-sitemap 插件,在发布和更新文章,出现的 PHP Warning: Illegal string offset 'lc_is_update_sitemap_when_post' in...... baidu-sitemap-generator\baidu_sitemap.php ,是因为缺少 isset 而出现警告。当访问未定义变量时,PHP 会产生警告;因此需要用 empty() 或者 isset() 判断变量是否定义。

baidu-sitemap.php 文件中的第 406 行:

if($get_baidu_sitemap_options['lc_is_update_sitemap_when_post'] == '1')

修改为:

if(isset($get_baidu_sitemap_options['lc_is_update_sitemap_when_post']) == '1')

修改日历年月样式
general-template.php 文件中的第 2012 行:

$wp_locale->get_month( $thismonth ),

修改为:

$wp_locale->get_month_abbrev( $wp_locale->get_month( $thismonth ) ),

修改文章归档日期样式

$text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );

修改为:

$text = sprintf( __( '%1$s &#x5E74; %2$s &#x6708;' ), $result->year, zeroise( $result->month, 2 ) );

参考资料:

作者: YesSan

和凡人一样,经历着万物的成长,衰败以及最终的死亡。理想主义的完美主义的个人英雄主义者。

发表回复

您的电子邮箱地址不会被公开。