Preload and mobile/desktop visibility conditions

If your website displays different content for desktop and mobile based on the visitor's operating system (Linux, Macintosh, Windows, Android, IOS), our desktop User-Agent used by the Preload feature may not generate the correct results.

When you set visibility conditions based on the desktop OS, the Preload feature may cause those elements to be hidden on the desktop.


Plugins/themes that use this type of detection

  • Divi’s Condition Options
  • Block Visibility
  • Premium Addons for Elementor

Solution

In order to solve this, you can customize the Preload User-Agent.

Add the following code snippet to the functions.php of your child theme, or use a code snippets plugin. Reference: How to add code snippets.

function custom_user_agent( $args ) {
	$args[0]['headers']['user-agent'] = 'WP Rocket/Preload - Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36';
	return $args;
}
add_filter( 'rocket_preload_before_preload_url', __NAMESPACE__ .'\custom_user_agent', PHP_INT_MAX );
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.