Created
April 27, 2017 13:37
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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