LivewireLaravelTips and TricksWeb DevelopmentTips

Jan 22, 2024

Dealing with the meta seo tag and open graph in Livewire 3 Volt

By Antoni Putra, Fullstack Web Developer

Dealing with the meta seo tag and open graph in Livewire 3 Volt

At beginning I was thinking this is trivial task to do. However, after start working on it I figured it out it's tricky to solve.

The best solution as I see for this is using blade @section, @show, @endsection syntax. Take a look at this example below.

You have layout file like this:

layouts/default.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
&lt;meta charSet="utf-8"/&gt;
&lt;meta name="viewport" content="width=device-width, initial-scale=1"/&gt;

@section('metatags')
    &lt;title&gt;{{ config('site.meta.default_title') }} | Coding Wisely&lt;/title&gt;
    &lt;link rel="canonical" href="{{ url('/') }}" /&gt;

    &lt;meta name="description" content="{{ config('site.meta.description') }}"&gt;
    &lt;meta name="keywords" content="{{ config('site.meta.keywords') }}"&gt;
    &lt;meta property="og:title" content="{{ !empty($title) ? Str::finish($title, ' | Coding Wisely') : 'Coding Wisely' }}"&gt;
    &lt;meta property="og:description" content="{{ config('site.meta.og:description') }}"&gt;
    &lt;meta property="og:image" content="{{ asset('CodingWisely.png') }}"&gt;
    &lt;meta property="og:url" content="{{ url('/') }}"&gt;
    &lt;meta property="og:type" content="{{ config('site.meta.og:type') }}"&gt;
    &lt;meta property="og:site_name" content="{{ config('site.meta.site_name') }}"&gt;

    &lt;meta name="twitter:card" content="{{ asset('CodingWisely.png') }}"&gt;
    &lt;meta name="twitter:title" content="{{ !empty($title) ? Str::finish($title, ' | Coding Wisely') : 'Coding Wisely' }}"&gt;
    &lt;meta name="twitter:description" content="{{ config('site.meta.description') }}"&gt;
    &lt;meta name="twitter:image" content="{{ asset('CodingWisely.png') }}"&gt;
@show

</head> <body> <div class="flex flex-col min-h-screen"> <header>Awesome Header</header> <main class="flex-grow"> {{ $slot }} </main> <footer>Beautiful Footer</footer> </div> </body> </html>

As you can see from the above layout code, you will see @section('metatags') that we can easily overwrite when needed.

Pay attention we are using @show as closing instead of @endsection.

Then, in another page that you need to change the metatags, all you have to do is simply:

pages/somewhere.blade.php

<?php
use function Livewire\Volt{layout, title,state, mount};
use App\Models\Post;

layout('layouts.default');

state([ 'post' => null ]); mount(function($slug) { $this->post = Post::query() ->whereSlug($slug) ->where('active', true) ->with(['categories', 'tags']) ->firstOrFail(); }); ?>

@section('metatags')

&lt;title&gt;{{ $post-&gt;title }} | Coding Wisely&lt;/title&gt;
&lt;!-- Put other metatags specific for this page here --&gt;
&lt;!-- ... --&gt;

@endsection

<div class="flex flex-col mx-auto max-w-5xl "> ... </div>

That's all.

Other posts:

Breaking the Ice at Laracon: A Small Act That Changes Everything
Breaking the Ice at Laracon: A Small Act That Changes Everything

Feeling shy or like an imposter at a big tech conference? You’re not alone. At Laracon US, one kind gesture changed a developer’s whole experience – proving how powerful a simple introduction can be. In this post, I share that story, how we can make conferences more welcoming, and why I’ve started calling myself the Laravel Social API.

Vladimir NikolicVladimir Nikolic
Aug 2, 2025
Laravel.rs Meetup #1: A New Era for the Serbian Laravel Community
Laravel
Laravel.rs Meetup #1: A New Era for the Serbian Laravel Community

On May 10th, 2025, Laravel.rs officially launched its first-ever meetup in Temerin, bringing together developers from across Serbia for a night of lightning talks, community networking, and a shared love for Laravel. With inspiring talks, open discussions, and future plans for workshops and hackathons, this kickoff event marked the beginning of a vibrant new chapter for Laravel in Serbia. 🚀🇷🇸

Vladimir NikolicVladimir Nikolic
May 15, 2025
Code, Stress, and Recovery: My Path to a Healthier Developer Life
Tips and Tricks
Code, Stress, and Recovery: My Path to a Healthier Developer Life

For years, I ignored the signs of burnout—long hours, constant stress, and the fear of failure. It caught up with me. I landed in the emergency room. This is my story of hitting rock bottom and rebuilding my health, mindset, and career.

Vladimir NikolicVladimir Nikolic
Feb 28, 2025

Are you set to create something extraordinary?

Ready to take the next step? Let's work together to transform your ideas into reality. Contact us today to discuss how we can help you create impactful, user-centered solutions that drive success.

Contact Us