怎么去掉Performance optimized by Redis Object Cache

Redis Object Cache插件成功激活使用时,在网站前端页脚会出现注释内容,如:

<!--
Performance optimized by Redis Object Cache. Learn more: https://wprediscache.com

Retrieved 3665 objects (31 KB) from Redis using Predis (v1.1.9).
-->

如何将其去掉呢?

wp-content\plugins\redis-cache\includes\class-plugin.php文件中,约 875 行,将:

public function register_shutdown_hooks() {
    if ( ! defined( 'WP_REDIS_DISABLE_COMMENT' ) || ! WP_REDIS_DISABLE_COMMENT ) {
        add_action( 'shutdown', [ $this, 'maybe_print_comment' ], 0 );
    }
}

改为:

public function register_shutdown_hooks() {
    if ( ! defined( 'WP_REDIS_DISABLE_COMMENT' ) || ! WP_REDIS_DISABLE_COMMENT ) {
        // add_action( 'shutdown', [ $this, 'maybe_print_comment' ], 0 );
    }
}

其实官方提供了一个配置方法:WP_REDIS_DISABLE_COMMENT

参考文档:https://github.com/rhubarbgroup/redis-cache/wiki/Configuration-Options#wp_redis_disable_comment-default-not-set

wp-config.php增加:

define('WP_REDIS_CONFIG', [
	'WP_REDIS_DISABLE_COMMENT' => true,
]);

但是其实经过我测试,并不会生效,一开始并不知道是不是我的方法错了,最后向作者提问,才发现Redis Object Cache Pro才能使用WP_REDIS_CONFIG,那么WP_REDIS_DISABLE_COMMENT自然就无效了。

3 thoughts on “怎么去掉Performance optimized by Redis Object Cache

    1. 这个是有用的,直接在 redis-cache.php 里面添加这一行就可以了

发表回复

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