Skip to content

Instantly share code, notes, and snippets.

@glueckpress
Created April 27, 2017 13:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glueckpress/305c7af9fd4a8dac69d68a91730a62ea to your computer and use it in GitHub Desktop.
Save glueckpress/305c7af9fd4a8dac69d68a91730a62ea to your computer and use it in GitHub Desktop.
[WordPress][WP Rocket] Check if a visitor is WP Rocket’s preload user agent.
<?php
/**
* More about WP Rocket’s preload options in this document:
* @link http://docs.wp-rocket.me/article/8-how-the-cache-is-preloaded
*/
/**
* Check if a visitor is WP Rocket’s preload user agent (bot or sitemap).
* This will trigger only on a document that has not been cached yet.
*
* @return boolean True: visitor is preload UA, else false
*/
function wp_rocket__is_preload() {
return 'wprocketbot' === $_SERVER ['HTTP_USER_AGENT'] ? true : false;
}
/**
* Show to preload bot only.
*/
if ( wp_rocket__is_preload() ) {
// Displayed only for preload bot.
}
/**
* Hide from preload bot.
*/
if ( ! wp_rocket__is_preload() ) {
// Hidden from preload bot.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment