A Package to Help set up SEO in Your Laravel Project

A Package to Help set up SEO in Your Laravel Project

Easily set up SEO in your Laravel applications with the code4mk/lara-head package by Mostafa Kamal. Here’s an example of how you’d use this package to set Facebook Opengraph tags:

  "app_id" => [
  "url" => [
  "type" => [
    "property"=>"og:type", "content"=>"website"
  "title" => [
    "content"=>"Content Title"
  // ...

Then in your blade template you’d access to Opengraph settings and render them out with the following:

{!! Khead::getOg() !!}

Here’s another example of setting the viewport (i.e., from a controller) and then rendering it on the frontend:

Khead::setMeta('viewport', [
    "name" => "viewport",
    "content"=>"width=device-width, initial-scale=1"

// Render
{!! Khead::getMeta('viewport') !!}

To learn more about the full capabilities of this package, including source code, documentation, and examples, check out the project on GitHub at code4mk/lara-head.

I want to point out that this package is demonstrating using Blade’s unescape syntax. You should verify the underlying code you are using any time you intentionally don’t escape HTML—especially third-party code. Future upgrades are worth reevaluation to make sure the packages you use haven’t introduced any unintentional (or intentional) vulnerabilities.

Filed in: News


Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Backend Engineer
64 Robots
Senior Laravel Developer
Atlanta, GA
Helium LLC
Full-Stack Developer (JS - Vue.js, PHP - Laravel)
US Remote / Telecommute
TTEC Digital
Backend Engineer
Brooklyn, NY
Back-End Developer
Orlando, FL
Christ for all Nations
Senior Software Developer
Nashville, TN
Bernard Health
Full Stack PHP Developer – (Laravel & Vue.js) - local only
Salt Lake City, Utah