PHP web framework

Laravel OG Image Integration

Add automatic MyOG.social images to Laravel Blade layouts with request URL helpers and page-specific meta sections.

Prerequisites

  • A Laravel app with public pages rendered through Blade
  • Access to the base layout or SEO partial that renders head tags
  • A MyOG.social account with your domain added

How MyOG fits Laravel

Laravel Blade layouts are a good MyOG integration point because they render server-side head tags before social crawlers fetch the page.

Use url()->current() for the current public page URL, or pass a canonical URL from the controller when the route should ignore query parameters or aliases.

Sections and stacks let individual pages override or extend the shared metadata without duplicating the whole layout.

1

Choose a layout

MyOG detects page content and branding automatically. The layout only controls image composition.

2

Add the Laravel code

Blade layout snippet

Use this in your layout head or shared SEO component.

@php
  $pageUrl = $canonicalUrl ?? url()->current();
  $myogImageUrl = "https://api.myog.social/og?url=" . rawurlencode($pageUrl) . "&template=screenshot-right";
@endphp
<meta property="og:image" content="{{ $myogImageUrl }}" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image" content="{{ $myogImageUrl }}" />

Set $canonicalUrl in a controller or view when the request URL is not the URL you want crawlers to share.

3

Place it correctly

  1. Find resources/views/layouts/app.blade.php or your SEO partial.
  2. Build the MyOG image URL from a canonical URL variable or url()->current().
  3. Place the tags next to existing Open Graph and Twitter card tags.
  4. Deploy, then inspect the HTML source for a route page and a model detail page.

Avoid duplicate og:image tags

Laravel apps often use SEO packages or custom Blade components that already render og:image. Replace the image value there or skip the fallback when a page-specific image section is present.

Dynamic pages

Use controller data for posts, products, and localized pages when canonical URLs need route helpers. url()->current() is fine for straightforward public routes.

Test the result

  • Check the deployed HTML response, not only browser devtools after hydration.
  • Test one dynamic route that uses model binding or slugs.
  • Confirm APP_URL and trusted proxy settings match the production domain.

Start with the MyOG Open Graph Checker, then refresh social platform caches if needed.

Known limitations

Queued previews, signed routes, and authenticated pages are not useful public OG image targets.
Wrong APP_URL or proxy configuration can produce incorrect absolute URLs.
If an SEO package renders image tags after your layout snippet, tag order can still affect crawler choice.

Sources

Ready to get started?

Sign up for free and add generated social images to Laravel pages.

Already have an account?

cdf733b534ea2f2ed964d150330b323c44837e4f