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:

Khead::setOg([
  "app_id" => [
    "property"=>"fb:app_id",
    "content"=>"123456789"
  ],
  "url" => [
    "property"=>"og:url",
    "content"=>"https://example.com/page.html"
  ],
  "type" => [
    "property"=>"og:type", "content"=>"website"
  ],
  "title" => [
    "property"=>"og: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


Newsletter

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

Laravel News Partners

Laravel Jobs

Full Stack Developer (Laravel/Vue.JS)
London, UK or Remote (UK only)
hullo Ltd
Senior Web Developer
San Diego, CA
Platform Science
Laravel Developer
San Jose, CA
X3 Builders
Lead Front End Developer
Remote
continued
Full-Stack Laravel Developer
Cologne
Revive Interior
Intermediate PHP Developer (Full Stack | CakePHP | Laravel | Vue | jQuery)
Remote
continued
Senior PHP Developer (Full Stack | CakePHP | Laravel | Vue | jQuery)
Remote
continued