Title: Solution: Exclude geolocation function from being cached by Cache Enabler plugin
Last modified: October 1, 2020

---

# Solution: Exclude geolocation function from being cached by Cache Enabler plugin

 *  [John](https://wordpress.org/support/users/casinobike/)
 * (@casinobike)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/solution-exclude-geolocation-function-from-being-cached-by-cache-enabler-plugin/)
 * Hello everyone!
    Maybe someone will find the solution I’ve implemented on my 
   website [CasinoBike.com](https://casinobike.com/) that has a geolocation function
   useful. As many know geotargeting is not very “friendly” with cache plugins. 
   The Cache Enabler plugin is not an exception either. But I found it a quite simple
   solution. You have to add “define(‘DONOTCACHEPAGE’, true);” in your theme’s specific
   php file to exclude it from cache.
 * Example:
    My theme has a file called geo.php. This file contains a geolocation
   api. You must edit this file in the notepad or notepad ++ and add the following
   line:
 *     ```
       <?php
       define('DONOTCACHEPAGE', true);
   
       /*
       Template Name: Geolocation
       */
   
       get_header(); ...
       ...
       ...
       ```
   
 * After adding this line, the Cache Enabler plugin will exclude this page from 
   caching.
 * Also, you may have a cache problem with the Autoptimize plugin. To exclude any
   file from cache in Autoptimize plugin, add the code in your functions.php file.
   Before the closing ?> tag.
 *     ```
       /* Autoptimize plugin exclude any page from cached */
       add_filter('autoptimize_filter_noptimize','noptimize_quiz',10,1);
       function noptimize_quiz($flag_in) {
       	if (strpos($_SERVER['REQUEST_URI'],'<FULL YOUR URL>')!==false) {
       		return true;
       	} else {
       		return $flag_in;
       	}
       }
       ```
   
 * Warning! Only for those users who have advanced knowledge in writing php code
   in CMS WordPress.
    -  This topic was modified 5 years, 8 months ago by [John](https://wordpress.org/support/users/casinobike/).

The topic ‘Solution: Exclude geolocation function from being cached by Cache Enabler
plugin’ is closed to new replies.

 * ![](https://ps.w.org/cache-enabler/assets/icon.svg?rev=2442383)
 * [Cache Enabler](https://wordpress.org/plugins/cache-enabler/)
 * [Support Threads](https://wordpress.org/support/plugin/cache-enabler/)
 * [Active Topics](https://wordpress.org/support/plugin/cache-enabler/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cache-enabler/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cache-enabler/reviews/)

## Tags

 * [Autoptimize Plugin](https://wordpress.org/support/topic-tag/autoptimize-plugin/)

 * 0 replies
 * 1 participant
 * Last reply from: [John](https://wordpress.org/support/users/casinobike/)
 * Last activity: [5 years, 8 months ago](https://wordpress.org/support/topic/solution-exclude-geolocation-function-from-being-cached-by-cache-enabler-plugin/)
 * Status: not a support question