Skip to content

Commit e488a91

Browse files
committed
Improve OG tags
1 parent 4a78da2 commit e488a91

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

app/Http/Controllers/ShowBlogController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Controllers;
44

55
use App\Models\Article;
6+
use Artesaos\SEOTools\Facades\SEOTools;
67

78
class ShowBlogController extends Controller
89
{
@@ -21,6 +22,19 @@ public function show(Article $article)
2122
{
2223
abort_unless($article->isPublished() || auth()->user()?->isAdmin(), 404);
2324

25+
// Set SEO metadata for the article
26+
SEOTools::setTitle($article->title . ' - Blog');
27+
SEOTools::setDescription($article->excerpt ?: 'Read this article on the NativePHP blog.');
28+
29+
// Set OpenGraph metadata
30+
SEOTools::opengraph()->setTitle($article->title);
31+
SEOTools::opengraph()->setDescription($article->excerpt ?: 'Read this article on the NativePHP blog.');
32+
SEOTools::opengraph()->setType('article');
33+
34+
// Set Twitter Card metadata
35+
SEOTools::twitter()->setTitle($article->title);
36+
SEOTools::twitter()->setDescription($article->excerpt ?: 'Read this article on the NativePHP blog.');
37+
2438
return view('article', [
2539
'article' => $article,
2640
]);

resources/views/components/layout.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
$defaultSeoTitle = config('seotools.meta.defaults.title');
5656
@endphp
5757

58-
@if ($seoTitle === $defaultSeoTitle || empty($seoTitle))
58+
@if ($seoTitle === $defaultSeoTitle)
5959
<title>{{ isset($title) ? $title . ' - ' : '' }}NativePHP</title>
6060
@endif
6161

0 commit comments

Comments
 (0)