diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php
index 6146e8d..48af709 100644
--- a/resources/lang/en/general.php
+++ b/resources/lang/en/general.php
@@ -57,6 +57,13 @@
'display' => 'No Index',
'instruct' => 'Prevent indexing across the entire site.',
],
+ 'default_locale_section' => [
+ 'display' => 'Default Locale',
+ 'instruct' => 'Select a locale to use as a default hreflang tag (see [https://developers.google.com/search/blog/2013/04/x-default-hreflang-for-international-pages](https://developers.google.com/search/blog/2013/04/x-default-hreflang-for-international-pages)).',
+ ],
+ 'default_locale' => [
+ 'display' => 'Default Locale',
+ ],
]
];
diff --git a/resources/views/tags/hreflang.antlers.html b/resources/views/tags/hreflang.antlers.html
index 640f9a4..3a97857 100644
--- a/resources/views/tags/hreflang.antlers.html
+++ b/resources/views/tags/hreflang.antlers.html
@@ -1,5 +1,8 @@
{{ if hreflang_tags }}
{{ hreflang_tags }}
+ {{ if default }}
+
+ {{ /if }}
{{ /hreflang_tags }}
{{ /if }}
diff --git a/src/Blueprints/CP/GeneralSettingsBlueprint.php b/src/Blueprints/CP/GeneralSettingsBlueprint.php
index 4c2989b..fb16a47 100644
--- a/src/Blueprints/CP/GeneralSettingsBlueprint.php
+++ b/src/Blueprints/CP/GeneralSettingsBlueprint.php
@@ -157,6 +157,22 @@ public static function requestBlueprint()
'instructions' => __('aardvark-seo::general.fields.no_index_site.instruct'),
],
],
+ [
+ 'handle' => 'default_locale_section',
+ 'field' => [
+ 'type' => 'section',
+ 'display' => __('aardvark-seo::general.fields.default_locale_section.display'),
+ 'instructions' => __('aardvark-seo::general.fields.default_locale_section.instruct'),
+ ],
+ ],
+ [
+ 'handle' => 'default_locale',
+ 'field' => [
+ 'type' => 'sites',
+ 'max_items' => 1,
+ 'display' => __('aardvark-seo::general.fields.default_locale.display'),
+ ],
+ ],
],
],
],
diff --git a/src/Modifiers/ParseLocaleModifier.php b/src/Modifiers/ParseLocaleModifier.php
index 61140e7..640e28f 100644
--- a/src/Modifiers/ParseLocaleModifier.php
+++ b/src/Modifiers/ParseLocaleModifier.php
@@ -11,6 +11,10 @@ class ParseLocaleModifier extends Modifier
public static function index($value)
{
+ if($value === 'x-default') {
+ return $value;
+ }
+
$parsed = preg_replace('/\.utf8/i', '', $value);
// Convert to W3C
diff --git a/src/Tags/AardvarkSeoTags.php b/src/Tags/AardvarkSeoTags.php
index bde5833..237780c 100644
--- a/src/Tags/AardvarkSeoTags.php
+++ b/src/Tags/AardvarkSeoTags.php
@@ -101,19 +101,27 @@ public function hreflang()
return null;
}
+
+ $defaultLocale = $ctx->get('aardvark_general_settings')['default_locale'];
+
+ if ($defaultLocale instanceof \Statamic\Fields\Value) {
+ $defaultLocale = $defaultLocale->value();
+ }
+
$sites_by_handle = Site::all()->reduce(function($sites, $site) {
$sites[$site->handle()] = $site;
return $sites;
}, []);
- $alternates = $data->sites()->map(function ($handle) use ($data, $sites_by_handle) {
+ $alternates = $data->sites()->map(function ($handle) use ($data, $sites_by_handle, $defaultLocale) {
$localized_data = $data->in($handle);
if(!empty($localized_data) && $localized_data->published()) {
$site = $sites_by_handle[$handle];
return [
'url' => $localized_data->absoluteUrl(),
- 'locale' => $site->locale()
+ 'locale' => $site->locale(),
+ 'default' => !empty($defaultLocale) ? $site->handle === $defaultLocale->handle : false,
];
}