Region redirects
If your Arlo platform has more than one region, the plugin redirects visitors to a regional address, such as /events/region-DE/. That suits most sites. If your site manages regional addresses itself, you can cancel or change those redirects with a filter, without editing the plugin.
Contents
- How the automatic redirect works
- When to change it
- The arlo_region_redirect_location filter
- Examples
- Checking your setup
How the automatic redirect works
Regional pages have the region in their address, as a /region- segment at the end. When a visitor opens a regionalized page without a region in the address, such as /events/, the plugin:
- Chooses a region: the one in the visitor's
arlo-regioncookie, or the first region on the Regions tab if there is no valid cookie. - Saves that region in the cookie.
- Runs the arlo_region_redirect_location filter, which can cancel or change the redirect.
- Sends a temporary (
302) redirect to the regional address, such as/events/region-DE/.
This applies to the host pages for the catalogue, schedule, upcoming events, event search and online activities, and to individual event pages. Pages that already have a region in the address, and pages that are not regionalized, are not redirected.
When to change it
The default suits a single site that serves every region from the same address. It works against you if you publish a separate address for each region and tell search engines about them with hreflang annotations, which is common on a WordPress multisite where each region is its own site, such as /en-us/ and /de-de/.
Search engines expect each address in an hreflang set to respond with 200 OK itself. An address that answers with a redirect (any 3xx) is not a valid alternate and may be ignored. Crawlers also do not keep cookies, so every crawl of a region-less address is sent to the first region. If your site manages its regional addresses, cancel the automatic redirect so those addresses respond directly.
Cancelling stops the redirect, nothing else
Arlo still chooses the region, from the address, the cookie or the first region. It does not map a prefix such as /de-de/ to a region, so each site needs its own Regions settings.
Some addresses Arlo builds, such as category and event links and the canonical link, still include /region-. They return 200, but check that your canonical and hreflang tags agree. Arlo does not output hreflang tags. They come from your SEO plugin, theme or site code.
arlo_region_redirect_location
A filter that runs just before the plugin sends an automatic region redirect. The visitor's region is saved and applied to the current request whatever you return.
Structure
add_filter(
'arlo_region_redirect_location',
function (
$target_location, $region, $request_uri,
$page_id, $region_source, $page_type
) {
return $target_location;
},
10,
6
);
The callback receives up to six arguments. Pass the number you accept as the last argument to add_filter(), or WordPress passes only the first.
Arguments
| Argument | Type / values | Description |
|---|---|---|
| $target_location | String | The proposed destination, a root-relative path and query string such as /events/region-DE/. Return it unchanged to keep the redirect. |
| $region | String | The region ID Arlo chose: from the visitor's cookie, or the first configured region when there is none. |
| $request_uri | String | The original request address, including its query string. |
| $page_id | Integer | The ID of the host page or event being viewed. |
| $region_source | Option: cookiedefault | cookie when the visitor had a valid saved region, otherwise default. Missing, invalid and unrecognised cookies all count as default. |
| $page_type | Option: eventseventupcomingscheduleeventsearchoa | events is the catalogue and event an individual event. The value is empty for a custom shortcode page. |
Return value
| Return | Result |
|---|---|
The $target_location you were given | The normal redirect. |
A root-relative path, such as /de-de/choose-region/ | Redirects there. It must start with a single /, and is relative to the site's root, not the current page. |
An absolute URL, such as https://example.org/choose-region/ | Redirects there. It must use http or https and include a host. The redirect uses wp_safe_redirect(), so the host must be your own site or one allowed by the allowed_redirect_hosts filter. Otherwise WordPress sends the visitor to /wp-admin/ instead. |
false, an empty string, or anything that is not a supported address | Cancels the redirect. The page renders normally at the requested address. |
A query string or fragment may follow a path or URL, but cannot stand alone. A result that points back at the page being viewed also cancels the redirect, so a rewrite cannot cause a loop.
Anything else cancels the redirect, including null, '0', arrays and numbers, and addresses that are not root-relative or absolute, such as events/, //example.org/events/, ?view=all and #dates.
Notes
- Use
$page_typeto tell the catalogue from an event page. Do not rely on WordPress conditionals such asis_single(), because Arlo changes the query flags. In a policy for specific page types, return$target_locationunchanged for any type you do not handle, including the empty one. - By the time the filter runs, the region is already saved in the cookie and applied to the request. Use
$region_sourceto tell a returning visitor from a first visit, and do not check for the cookie yourself. - The filter does not run for a host page that is not published, or for pages that already have a region in the address. Cancelling does not make an unpublished or missing page render.
- If several callbacks are registered, they run in priority order and each receives the previous result.
Examples
Put the code where it is kept with your site and not inside the Arlo plugin, which would lose it on the next update. A must-use plugin is the simplest option: save a PHP file such as wp-content/mu-plugins/site-arlo-region-policy.php. WordPress loads it automatically and it needs no activation. A site-specific plugin also works. On multisite an MU-plugin loads for every subsite, so check get_current_blog_id() in your callback if the policy should apply to only some of them.
Cancel every redirect
This suits a site where the regional addresses are managed by your own setup, such as a separate site for each region:
<?php
/**
* Plugin Name: Site Arlo Region Policy
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_filter( 'arlo_region_redirect_location', '__return_false' );
Cancel for first-time visitors on some pages
Cancel only when the visitor has no saved region, and only on the catalogue and schedule pages. Everyone else is redirected as usual:
add_filter(
'arlo_region_redirect_location',
function (
$target, $region, $request_uri,
$page_id, $region_source, $page_type
) {
if ( ! in_array( $page_type, array( 'events', 'schedule' ), true ) ) {
return $target;
}
return 'default' === $region_source ? false : $target;
},
10,
6
);
Send first-time visitors to your own page
Send visitors who have no saved region to a page where they choose one. Visitors who already have a region still get the normal redirect:
add_filter(
'arlo_region_redirect_location',
function ( $target, $region, $request_uri, $page_id, $region_source ) {
if ( 'default' === $region_source ) {
return home_url( '/choose-region/' );
}
return $target;
},
10,
5
);
Arlo has already saved its default region in the cookie by then, so a visitor who skips your page and returns is treated as having that region. Link your region choices to the regional addresses, such as /events/region-DE/, so choosing one replaces it.
Checking your setup
Test on a staging copy first. For each regional page, try a visitor with no cookie, with a valid arlo-region cookie, and with an unrecognised one. Confirm:
- The response status, and the
Locationheader if it redirects. - The region cookie that was set.
- That the page shows the content for the region you expect. A
200alone does not prove that.
You can check the status from the command line. A page whose redirect is cancelled should answer 200:
curl -sI https://example.org/de-de/events/ | head -n 1 HTTP/2 200
Also check through any page cache or CDN, since a cached redirect can outlast a change to your code.
