We noticed you're using an ad blocker

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Dynamic SEO meta-tags in Laravel website

world cup 2022


Get update standing EPL, UEFA, LaLiga and more

Get Now

For getting much organic traffic from the search engine like Google, Bing, Yahoo etc on a website there are many ways but adding meta tags on webpages is the most important one. The SEO meta tags define your webpage content summary and information about your content that helps the search engine to show on SERP (Search Engine Results Pages). In Laravel, we can make these meta tags dynamically. You can generate tags using third party packages or from scratch. Here in this post, I'll show you step by step process for generating SEO meta tags in your Laravel website from scratch without using any packages. When we'll use meta tags into our webpages it'll show the SERP looks like below.



Steps for generating dynamic SEO meta tags

  1. Add yield to the site template.
  2. Add keyword and description field.
  3. Make panel for adding & updating meta tags.
  4. Generate meta tags on pages.


Step 01: Add yield to the site template

First, add some yield fields into your site template. Suppose your site template is template.blade.php into resources/views/frontend directory. Let's add the yield fields.

    <title>@yield('title','A default title')</title>
    <meta name="keywords" content="@yield('meta_keywords','some default keywords')">
    <meta name="description" content="@yield('meta_description','default description')">
    <link rel="canonical" href="{{url()->current()}}"/>

N.B: Do not forget to change the default value according to your needs.


Step 02: Add keyword and description field

Now add two new fields into your posts/articles table where you save your post.



Step 03: Make a panel for adding & updating meta tags.

Do markup for adding/updating meta tags into your post create and update form.

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">Meta Tags</h3>
    <div class="panel-body">
    	<div class="form-group">
    		<input name="meta_keywords" class="form-control">
    	<div class="form-group">
    		<input name="meta_description" class="form-control">


Now do the code for saving & updating in your controller.

public function store(Request $request){
	// your previous code

	$post->meta_keywords = $request->get('meta_keywords');
	$post->meta_description = $request->get('meta_description');

public function update(Request $request){
	// your previous code

	$post->meta_keywords = $request->get('meta_keywords');
	$post->meta_description = $request->get('meta_description');


Step 04: Generate meta tags on pages.

Open the post details blade template and add the code given below. For example, our post details blade template file name is single.blade.php

@section('title', $post->title)
@section('meta_keywords', $post->meta_keywords)
@section('meta_description', $post->meta_description)


<!--your post content -->



We are done! Now we can add our meta keywords and meta description for every post dynamically and it will automatically generate SEO meta tags for us in every post details page. We can also add meta tags in our static pages by adding a section on those pages.

@section('title', 'Contact Us')
@section('meta_keywords','contact,contact us')
@section('meta_description', 'Contact page of example.com')


<!--your page content -->



Hopefully, this post will help you to add SEO meta tags in your Laravel website. If this step by step post helpful to you for learning dynamic SEO meta tags adding in Laravel website then share it with others so that it'll be helpful for them.


Share on

Related Post - Latest Post

Tinkerpad - A minimal Laravel code editor

Ultimate Laravel SEO guide in 2022

Generate SEO friendly URL in Laravel

Generate dynamic sitemap in Laravel - SEO