1. 我是皮皮虾首页
  2. 网站部署

wordpress 时区设置问题,相差8个小时

问题

每次发布新文章的时候,在前端页面都显示8小时前,这明显是时区有问题。

wordpress 时区设置问题,相差8个小时

排查问题

  • 排查是否是系统时间的问题
    • 进入到服务器,直接date
[root@centos7 ~]# date
Wed Jul  7 20:10:33 CST 2021
  • 排查是否是设置问题
wordpress 时区设置问题,相差8个小时
  • 不是系统问题,那就php、wordpress、主题的问题
  • php的问题
    • 可以修改/www/server/php/74/etc/php.ini文件,修改为date.timezone = “Asia/Shanghai”
  • wordpress的问题
    • 在/wp-includes/functions.php中,<?php 后面2到3行后加入:date_default_timezone_set(‘Asia/Shanghai’);
  • 如果前面几种方式都没有解决,那就是主题的问题,先切换到默认主题,查看时间是否问题,如果默认主题没有问题,那就是当前用到的主题有问题
    • 在主题代码里面的footer.php最后面增加一行代码
<script type="text/javascript">
alert(""+<?php echo current_time('timestamp'); ?>);
</script>
  • 刷新自己的网站,会弹出时间戳,将这个时间戳在服务中输入代码,可以看到具体时间,会发现提前8小时,那就确定是主题的问题
    • LANG=”utf-8″ date -d @时间戳
    • 我的问题是这样解决的,进入主题跟目录
      • grep “get_the_date” -rn ./
      • 然后发现这个文件刚好有问题 vim ./inc/theme-functions.php ,里面有行代码被注释并替换了,我修改回去了就行
[root@centos-web-service ripro]# grep "get_the_date" -rn ./
./inc/theme-functions.php:149:            echo '<a'._target_blank().' href="'.esc_url(get_the_permalink($post_id)).'"><time datetime="'.get_the_date('c', $post_id).'">'._get_post_time().'</time></a>';
./inc/theme-functions.php:1111:    // return (time() - strtotime(get_the_time('Y-m-d'))) > 86400 ? get_the_date() : get_the_time();
./parts/entry-footer.php:6:      <time datetime="<?php echo esc_attr( get_the_date( 'c' ) ); ?>"><?php echo '<i class="fa fa-clock-o"></i> '._get_post_time();?></time>
[root@centos-web-service ripro]# vim ./inc/theme-functions.php

原创文章,作者:站长,如若转载,请注明出处:https://wsppx.cn/348/%e7%bd%91%e7%ab%99%e9%83%a8%e7%bd%b2/

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注