方法一

通过检索wp-includes/functions.php内容修改gmt值(默认为0)为8

function current_time( $type, $gmt = 0 ) {
        // Don't use non-GMT timestamp, unless you know the difference and really need to.
        if ( 'timestamp' === $type || 'U' === $type ) {
                return $gmt ? time() : time() + (int) ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
        }

        if ( 'mysql' === $type ) {
                $type = 'Y-m-d H:i:s';
        }

        $timezone = $gmt ? new DateTimeZone( 'UTC' ) : wp_timezone();
        $datetime = new DateTime( 'now', $timezone );

        return $datetime->format( $type );
}

在wordpress程序目录执行如下命令:

sed -i 's/\(^f.*current_time.*=[[:space:]]\)[0-9]\(.*\)/\18\2/' wp-includes/functions.php
方法二

修改主题文件inc/views/blog/class-hestia-blog-post-layout.php

        private function get_time_tags() {
                $time = '';

                $time .= '<time class="entry-date published" datetime="' . esc_attr( get_the_date( 'c' ) ) . '" content="' . esc_attr( get_the_date( 'Y-m-d' ) ) . '">';
                $time .= esc_html( human_time_diff( get_the_time( 'U' ), time() ) );
                $time .= '</time>';
                if ( get_the_time( 'U' ) === get_the_modified_time( 'U' ) ) {
                        return $time;
                }
                $time .= '<time class="updated hestia-hidden" datetime="' . esc_attr( get_the_modified_date( 'c' ) ) . '">';
                $time .= esc_html( human_time_diff( get_the_modified_date( 'U' ), time() ) );
                $time .= '</time>';
                
                return $time;
        }

修改为:

        private function get_time_tags() {
                $time = '';

                $time .= '<time class="entry-date published" datetime="' . esc_attr( get_the_date( 'c' ) ) . '" content="' . esc_attr( get_the_date( 'Y-m-d' ) ) . '">';
                $time .= esc_html( human_time_diff( get_the_time( 'U' ), current_time('timestamp') ) );
                $time .= '</time>';
                if ( get_the_time( 'U' ) === get_the_modified_time( 'U' ) ) {
                        return $time;
                }
                $time .= '<time class="updated hestia-hidden" datetime="' . esc_attr( get_the_modified_date( 'c' ) ) . '">';
                $time .= esc_html( human_time_diff( get_the_modified_date( 'U' ), current_time('timestamp') ) );
                $time .= '</time>';
                
                return $time;
        }
效果

修改前

修改后


该文章采用「CC 协议」,转载必须注明作者和本文链接.
分类: PHP