diff --git a/src/Models/SEO.php b/src/Models/SEO.php
index 23e26c2..94e0051 100644
--- a/src/Models/SEO.php
+++ b/src/Models/SEO.php
@@ -47,6 +47,7 @@ public function prepareForUsage(): SEOData
locale: $overrides->locale ?? null,
robots: $overrides->robots ?? $this->robots,
canonical_url: $overrides->canonical_url ?? $this->canonical_url,
+ openGraphTitle: $overrides->openGraphTitle ?? null,
);
}
}
\ No newline at end of file
diff --git a/src/Support/SEOData.php b/src/Support/SEOData.php
index 95955a3..5d0e7c2 100644
--- a/src/Support/SEOData.php
+++ b/src/Support/SEOData.php
@@ -32,6 +32,7 @@ public function __construct(
public ?string $locale = null,
public ?string $robots = null,
public ?string $canonical_url = null,
+ public ?string $openGraphTitle = null,
) {
if ( $this->locale === null ) {
$this->locale = app()->getLocale();
diff --git a/src/TagManager.php b/src/TagManager.php
index 168aa07..4fc7349 100644
--- a/src/TagManager.php
+++ b/src/TagManager.php
@@ -45,6 +45,10 @@ public function fillSEOData(SEOData $SEOData = null): SEOData
if ( $SEOData->enableTitleSuffix ) {
$SEOData->title .= config('seo.title.suffix');
+
+ if ($SEOData->openGraphTitle) {
+ $SEOData->openGraphTitle .= config('seo.title.suffix');
+ }
}
if ( $SEOData->image && ! filter_var($SEOData->image, FILTER_VALIDATE_URL) ) {
diff --git a/src/Tags/OpenGraphTags.php b/src/Tags/OpenGraphTags.php
index 399ba8d..a2799a7 100644
--- a/src/Tags/OpenGraphTags.php
+++ b/src/Tags/OpenGraphTags.php
@@ -17,7 +17,9 @@ public static function initialize(SEOData $SEOData): static
{
$collection = new static();
- if ( $SEOData->title ) {
+ if ( $SEOData->openGraphTitle ) {
+ $collection->push(new OpenGraphTag('title', $SEOData->openGraphTitle));
+ } else if ( $SEOData->title ) {
$collection->push(new OpenGraphTag('title', $SEOData->title));
}
diff --git a/src/Tags/TwitterCardTags.php b/src/Tags/TwitterCardTags.php
index cb6b5bd..524a8e6 100644
--- a/src/Tags/TwitterCardTags.php
+++ b/src/Tags/TwitterCardTags.php
@@ -31,7 +31,9 @@ public static function initialize(SEOData $SEOData): ?static
$collection->push(new TwitterCardTag('card', 'summary'));
}
- if ( $SEOData->title ) {
+ if ( $SEOData->openGraphTitle ) {
+ $collection->push(new TwitterCardTag('title', $SEOData->openGraphTitle));
+ } else if ( $SEOData->title ) {
$collection->push(new TwitterCardTag('title', $SEOData->title));
}
diff --git a/tests/Feature/Tags/OpenGraphTagsTest.php b/tests/Feature/Tags/OpenGraphTagsTest.php
index 2a985fd..974c5b5 100644
--- a/tests/Feature/Tags/OpenGraphTagsTest.php
+++ b/tests/Feature/Tags/OpenGraphTagsTest.php
@@ -122,3 +122,20 @@
get(route('seo.test-plain'))
->assertSee('', false);
});
+
+it('uses openGraphTitle over title', function() {
+ config()->set('seo.title.suffix', ' | Laravel SEO');
+
+ $page = Page::create();
+ $page::$overrides = [
+ 'openGraphTitle' => 'My OG title',
+ ];
+ $page->seo->update([
+ 'title' => 'My page title',
+ ]);
+
+ $page->refresh();
+
+ get(route('seo.test-page', ['page' => $page]))
+ ->assertSee('', false);
+});
diff --git a/tests/Feature/Tags/TwitterCardSummaryTagsTest.php b/tests/Feature/Tags/TwitterCardSummaryTagsTest.php
index 6aba7b8..36584dd 100644
--- a/tests/Feature/Tags/TwitterCardSummaryTagsTest.php
+++ b/tests/Feature/Tags/TwitterCardSummaryTagsTest.php
@@ -91,4 +91,23 @@
})->with([
['images/twitter-72x72.jpg'],
['images/twitter-4721x4721.jpg'],
-]);
\ No newline at end of file
+]);
+
+
+
+it('uses openGraphTitle over title', function() {
+ config()->set('seo.title.suffix', ' | Laravel SEO');
+
+ $page = Page::create();
+ $page::$overrides = [
+ 'openGraphTitle' => 'My OG title',
+ ];
+ $page->seo->update([
+ 'title' => 'My page title',
+ ]);
+
+ $page->refresh();
+
+ get(route('seo.test-page', ['page' => $page]))
+ ->assertSee('', false);
+});
\ No newline at end of file