Posted by Arjun on Saturday 22nd November 2014

Laravel Facebook Open Graph Macro

Here is a custom HTML macros for Facebook Open Graph meta tags. if you don't had any idea about FB open Graph meta tags , don't worry visit my previous post : Facebook Open Graph META Tags

Laravel allowing us to extend the HTML facade with additional functionality. we use the HTML::macro() method to extend the HTML facade with our own methods.

Facebook Open Graph meta tags Macro

HTML::macro('fbog', function($property, $content)
return '<meta property="og:'. $property .'" content="'. $content .'" />'. PHP_EOL;

How to use:

Place the above macro code into your app/start/global.php file to register it. Then place place this code in your views.

{{ HTML::fbOgMeta("type","profile") }}
{{ HTML::fbOgMeta("title","Website Name"); }}
{{ HTML::fbOgMeta("description","Website  Description") }}
{{ HTML::fbOgMeta("image","") }}
{{ HTML::fbOgMeta("url","") }}
{{ HTML::fbOgMeta("site_name","Website Name") }}
{{ HTML::fbOgMeta("see_also","") }}


you may get below output in your html source

<meta property="og:title" content="Website Name" />

<meta property="og:description" content="Website  Description" />

<meta property="og:image" content="" />

<meta property="og:url" content="" />

<meta property="og:site_name" content="Website Name" />

<meta property="og:see_also" content="" />