关于 Blog 修改

关于 Blog 修改

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

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

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

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

修改为:

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

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

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

修改为:

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

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

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

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

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

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

修改为:

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

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

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

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

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

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

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

修改为:

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

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

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>',

修改为:

1998
'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-generatoraidu_sitemap.php ,是因为缺少 isset 而出现警告。当访问未定义变量时,PHP 会产生警告;因此需要用 empty() 或者 isset() 判断变量是否定义。

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

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

修改为:

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

参考资料:





原文地址:https://www.cnblogs.com/jins-note/p/9513144.html