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 ); }
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’ ) ) {
Thanks for catching that. I’ve updated the code samples.
Great, exactly what I needed!
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!
Great.. it worked.. But I want remove also
<!– W3 Total Cache: Minify debug info:
Is there any idea for this ?
Go to the Debug section of Performance > General Settings and uncheck “Minify”.
I tried this but still see the following comments added in the footer:
—
—
Any help is highly appreciated.
Do you see the comment when logged out of WP?
Thanks for the nipper, works very well.
How about using WordPress __return_false function ?
http://codex.wordpress.org/Function_Reference/_return_false
Excellent! Works perfectly!
Thank you so much for sharing!
Blaise
thank you so much i’ll implementation
It’s work. Thank you 🙂
When I use this and I try to empty the cache, it’s returning a white blank screen.
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.
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.
I’ve updated the code samples to use __return_false (WP 3.0+), as previously suggested.
Many thanks, works fine.
thank you, it’s works!