AJAX mode

Ajax mode was conceived in order to make the Geotargeting plugin compatible with all cache plugins around. Once enabled, the shortcodes, geotargeted posts or products, redirects,etc will be updated after the page it's loaded by doing an AJAX request with Javascript. Thanks to this we are able to bypass the page cache generated by plugins.

Also AJAX mode it's needed when you use GPS Geolocation because the browser use javascript to get user's location.

Important:

  • Geotargeted categories are not supported by ajax.
  • Posts / products needs to be compliant with WordPress coding standards. This mean that each posts needs to have an ID attribute such as post-12 (where 12 is post ID ) or class attribute with same value. Also when content is replaced with a message the posts needs to have class attribute of “entry-content” in order to know where to place the message.
  • When you have geotarget posts, every page will consume a request*

Geo Redirect

The difference between this mode and regular mode is that the user sees the page for a second or less. Then, a full screen overlay it's presented to inform that he is being redirected to the right page.

Geo Blocker

The difference between this mode and regular mode is that the user sees the page for a second or less.Then, a full screen overlay it's presented to inform that the page it's not available to the user.

How to tweak AJAX mode to remove certain HTML?

Ajax mode provides some developer hooks that will let you tweak the remove or hide html class attributes on the callback. This is useful if for example you want to hide the WooCommerce add to cart button along with some other pieces of the html in the page.

To do that add in your theme's functions.php file the following code. The %id will be automatically replaced for the id. We use to match only the needed posts.


add_filter( 'geot/ajax_mode/hide_class' , function(){
        return '.post-%id .elementor-add-to-cart';
});
        
Available Hooks
  • geot/ajax_mode/hide_class: Add classes to the default hardcoded ones. hide_class works when "remove from loop" option is unchecked.
  • geot/ajax_mode/hide_override_class: Replace the default hardcoded classes with the ones provided by you.
  • geot/ajax_mode/remove_class: Add classes to the default hardcoded ones. remove_class works when "remove from loop" option is checked
  • geot/ajax_mode/remove_override_class: Replace the default hardcoded classes with the ones provided by you.

* About the extra requests

When ajax mode it's enabled the plugin will get a list of all posts of the site where you added geolocation even if not the queried page. This happens so those pages can be removed from widgets or similar elements. If you want to save requests because you know this functionality it's not needed you could add the following filter:


add_filter( 'geot/get_geotargeted_posts_pass_id', function( $pid, $ajax_data ) {
        // will save requests in all single pages and posts that are not geotargeted
        if( $ajax_data['is_singular'] ) {
           return $ajax_data['pid'];
        }
});
        

Javascript geolocation

When you have AJAX mode enable you can hook into the GeotargetingWP ajax response and have access to all the geolocation data to create your own functionality in Javascript.

Check out our WordPress geolocation solutions
to find out everything you can do!

Start your free trial