Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 65051

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

$
0
0

Replies: 0

Hello everyone!
Maybe someone will find the solution I’ve implemented on my website 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 39 minutes ago by John.

Viewing all articles
Browse latest Browse all 65051

Trending Articles