Disabling the W3 Total Cache Footer Comment

2016-07-01: Updated code samples to use __return_false instead of an anonymous function

By default, the W3 Total Cache (W3TC) WordPress plugin adds an HTML comment like the one below to the page footer.

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/ Database Caching using disk Object Caching 917/945 objects using disk Content Delivery Network via Amazon Web Services: S3: example.s3.amazonaws.com Served from: www.example.com @ 2014-01-14 17:57:58 by W3 Total Cache -->

To remove it without modifying the W3TC files (which would be overwritten when the plugin is upgraded), add one of the following to your functions.php.

// Disable W3TC footer comment for all users
add_filter( 'w3tc_can_print_comment', '__return_false', 10, 1 );
// Disable W3TC footer comment for everyone but Admins (single site) / Super Admins (network mode)
if ( !current_user_can( 'unfiltered_html' ) ) {
    add_filter( 'w3tc_can_print_comment', '__return_false', 10, 1 );
}
// Disable W3TC footer comment for everyone but Admins (single site & network mode)
if ( !current_user_can( 'activate_plugins' ) ) {
    add_filter( 'w3tc_can_print_comment', '__return_false', 10, 1 );
}

19 comments on “Disabling the W3 Total Cache Footer Comment

  1. Hi, thanks for this tip.
    You forgot the ! in the if instruction. Since default accounts are admins and not supper admin I suggest the following condition instead:
    if ( !current_user_can( ‘activate_plugins’ ) ) {

  2. Thanks for posting this, I added similar logic to Blubrry PowerPress to turn comments off for feeds. We’ve known for a while that HTML comments in the bottom of the feeds cause delays with iTunes listings, this solves that problem!

  3. Great.. it worked.. But I want remove also
    <!– W3 Total Cache: Minify debug info:

    Is there any idea for this ?

    • Turns out because the parent theme already had a functions.php the functions.php I created in the child theme cause some conflicting issues.

      I added it to the parent’s theme functions.php and it works fine now.

  4. Hello,

    Is there a PHP5 version of this vs. a 5.3+ version? Specifically we’re trying to use:

    // Disable W3TC footer comment for all users
    add_filter( ‘w3tc_can_print_comment’, function( $w3tc_setting ) { return false; }, 10, 1 );

    No matter what we’ve done including emptying caches…we cannot get his to work. Temporarily we went directly into the W3TC TotalCache.php file and forced it to not display.

    Thanks for your feedback.

Leave a Reply

Your email address will not be published. Required fields are marked *