Enable cache for Facebook user agent
The Facebook user agent is automatically excluded from being served cache files to prevent potential incompatibilities that could occur: for example, when a post/page is shared on Facebook.
If you want to serve cached pages to the Facebook bot instead (not recommended), then you can proceed with the following steps:
- Add the following code using one of the methods described in our Add Code Snippets article, or using an MU Plugin:
- Deactivate and reactivate WP Rocket plugin for the change to start working.
add_filter( 'rocket_cache_reject_ua', 'wprocket_remove_fb_ua' ); function wprocket_remove_fb_ua( $ua ) { if ( in_array( 'facebookexternalhit', $ua ) ) { $ua = array_flip( $ua ); unset( $ua[ 'facebookexternalhit' ] ); $ua = array_flip( $ua ); } return $ua; }