Skip to content

Instantly share code, notes, and snippets.

@Patabugen
Last active June 23, 2022 15:35
Show Gist options
  • Save Patabugen/7f88cdcc42b9e0fbd9ab8062404f33d5 to your computer and use it in GitHub Desktop.
Save Patabugen/7f88cdcc42b9e0fbd9ab8062404f33d5 to your computer and use it in GitHub Desktop.
Workaround for Simple Share Buttons and front end caching
<?php
/**
* The Simple Share Buttons uses wp_is_mobile() to decide how to render front end
* pages, which is incompatible with frontend caching. So filter the check
* to always return the "mobile version" (unless we are in the admin backend).
*
* Bbeware! It overrides _all_ frontend calls, not just SSBA ones).
*
* Save this as a mu-plugin ( wp-content/mu-plugins/disable-wp-is-mobile.php )
* or paste it into your functions.php file
*
* @see https://wordpress.org/support/topic/disable-wp_is_mobile-checks/
* @see https://developer.wordpress.org/reference/functions/wp_is_mobile/
*
*/
add_filter( 'wp_is_mobile', function($is_mobile){
if (!is_admin()) {
return true;
}
return $is_mobile;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment