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:

  1. Add the following code using one of the methods described in our Add Code Snippets article, or using an MU Plugin:
  2. 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;
    }
    	
  3. Deactivate and reactivate WP Rocket plugin for the change to start working.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.