WordPress隐藏评论日期的方法

原梓番
原梓番
管理员
827
文章
0
粉丝
建站 技术流35,697阅读模式

为什么会有这种奇怪的要求?文章源自原紫番博客-https://www.yuanzifan.com/54297.html

我不知道耶,客户提的。文章源自原紫番博客-https://www.yuanzifan.com/54297.html

修改方法:文章源自原紫番博客-https://www.yuanzifan.com/54297.html

打开/wp-includes/comment-template.php文章源自原紫番博客-https://www.yuanzifan.com/54297.html

500~600行之间,找到下列代码,将 $date=mysql2.。。的两行,都注释掉,前台评论即可隐藏日期。文章源自原紫番博客-https://www.yuanzifan.com/54297.html

但需要注意的是,如果升级了主题,则此操作会被覆盖。文章源自原紫番博客-https://www.yuanzifan.com/54297.html

 文章源自原紫番博客-https://www.yuanzifan.com/54297.html

 文章源自原紫番博客-https://www.yuanzifan.com/54297.html

function get_comment_date( $d = '', $comment_ID = 0 ) {
	$comment = get_comment( $comment_ID );
	if ( '' == $d ) {
		$date = mysql2date( get_option( 'date_format' ), $comment->comment_date );
	} else {
		$date = mysql2date( $d, $comment->comment_date );
	}
	/**
	 * Filters the returned comment date.
	 *
文章源自原紫番博客-https://www.yuanzifan.com/54297.html文章源自原紫番博客-https://www.yuanzifan.com/54297.html
站长微信
扫码添加(注明来意)
weinxin
Yuanzifan99
微信号已复制
原梓番博客公众号
博客内容精选
weinxin
原梓番博客
公众号已复制
 
评论  3  访客  2  作者  1
    • 大致 4

      改WP原代码不是好办法。用钩子函数吧。
      function custom_comment_date( $date, $d, $comment ) {
      return ;
      }
      add_filter( ‘get_comment_date’, ‘custom_comment_date’, 10, 3);

      function custom_comment_date( $date, $d, $comment, $translate, $comment ) {
      return ;
      }
      add_filter( ‘get_comment_time’, ‘custom_comment_time’, 10, 5);

        • 原梓番

          @ 大致 真的学习了,虽然我知道动源代码不好,但是我还是图省事动了……

          • 绿软吧(lvr8) 2

            @ 大致 感谢分享,谢谢站长!!

        发表评论

        匿名网友
        确定

        拖动滑块以完成验证