diff --git a/resources/views/metatags.antlers.html b/resources/views/metatags.antlers.html index 7d54485..df3297a 100644 --- a/resources/views/metatags.antlers.html +++ b/resources/views/metatags.antlers.html @@ -9,6 +9,12 @@ {{ /if }} +{{ unless settings | in_array:basic }} +{{ fields }} +{{ basic_title }} {{ extras.site_name_separator}} {{ extras.site_name}} +{{ /fields }} +{{ /unless }} + {{ if settings | in_array:advanced }} {{ fields }} diff --git a/src/Tags/MetatagsTags.php b/src/Tags/MetatagsTags.php index ce4665d..8594238 100644 --- a/src/Tags/MetatagsTags.php +++ b/src/Tags/MetatagsTags.php @@ -8,6 +8,7 @@ use Gioppy\StatamicMetatags\Settings; use Illuminate\Support\Str; use Statamic\Fields\Value; +use Statamic\Fieldtypes\Text; use Statamic\Support\Arr; use Statamic\Tags\Tags; @@ -45,9 +46,15 @@ public function index() { ->merge($pageFields); // Check if fields have title, otherwise load default title + if (array_key_exists('basic_title', $fields->all()) && !is_string($fields->only('basic_title')->all()['basic_title'])) { + $defaultTitle = $page->only('title')->all(); + $fields->prepend(new Value($defaultTitle['title'] ?? ' '), 'basic_title'); + } + + // If there is no basic_title, load page title if (!array_key_exists('basic_title', $fields->all())) { $defaultTitle = $page->only('title')->all(); - $fields->prepend(new Value($defaultTitle['title']), 'basic_title'); + $fields->prepend(new Value($defaultTitle['title'] ?? ' ', 'basic_title', new Text()), 'basic_title'); } return view('statamic-metatags::metatags', [