Install examples
Replace YOUR_SITE_KEY with the key from Checkout. Templates: blog, launch, changelog, docs.
HTML
One page, one og:image URL. Repeat the pattern on every page you care about.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"/> <title>Ship it</title> <meta property="og:title" content="Ship it"/> <meta property="og:description" content="A post on your site."/> <meta property="og:image" content="https://cardurl.dev/og/YOUR_SITE_KEY/blog?title=Ship+it"/> <meta property="og:image:width" content="1200"/> <meta property="og:image:height" content="630"/> </head> <body> <h1>Ship it</h1> </body> </html>
Next.js
App Router: return the CardURL URL from generateMetadata in each route that should get a card. One URL per page, built from that page's own title. This is not a set-once site setting.
1. A small helper
// app/cardurl.ts
const SITE_KEY = "YOUR_SITE_KEY";
export function cardUrl(
template: "blog" | "launch" | "changelog" | "docs",
params: Record<string, string>,
) {
const query = new URLSearchParams(params).toString();
return `https://cardurl.dev/og/${SITE_KEY}/${template}?${query}`;
}
URLSearchParams encodes each value, so titles with &, : or ? stay intact. If you build the string by hand, wrap each value in encodeURIComponent. Params per template: templates.
2. A dynamic route
// app/blog/[slug]/page.tsx
import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { cardUrl } from "../../cardurl";
import { getPost } from "../../posts"; // your data
type Props = { params: Promise<{ slug: string }> };
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { slug } = await params;
const post = await getPost(slug);
if (!post) notFound();
const image = cardUrl("blog", {
title: post.title,
date: post.date,
site: "yoursite.com",
});
return {
title: post.title,
description: post.description,
openGraph: {
title: post.title,
description: post.description,
type: "article",
images: [{ url: image, width: 1200, height: 630, alt: post.title }],
},
twitter: {
card: "summary_large_image",
images: [image],
},
};
}
3. What the page should render
For a post titled "Ship it: notes & lessons", next build then next start gave:
<meta property="og:image" content="https://cardurl.dev/og/YOUR_SITE_KEY/blog?title=Ship+it%3A+notes+%26+lessons&date=Oct+21%2C+2026&site=yoursite.com"/>
<meta property="og:image:width" content="1200"/>
<meta property="og:image:height" content="630"/>
<meta name="twitter:image" content="https://cardurl.dev/og/YOUR_SITE_KEY/blog?title=Ship+it%3A+notes+%26+lessons&date=Oct+21%2C+2026&site=yoursite.com"/>
The & is normal HTML escaping. Crawlers read it as &.
Things that trip people up
- metadataBase. The CardURL URL is absolute, so
metadataBasedoes not touch it. You still needmetadataBasefor any relative URL you set, like a canonical. A relative URL without it is a build error. (Next.js docs, read 2026-10-21.) - openGraph replaces, it does not merge. If a layout sets
openGraphand the page setsopenGraphtoo, the page's object wins whole. Put title and description in the page'sopenGraph, not only the image. (Next.js docs: Merging.) - Remove
opengraph-image.*files on routes that use CardURL. Next.js also readsopengraph-imageandtwitter-imagefiles placed in a route folder, and its docs say file-based metadata has higher priority thangenerateMetadata. In our test build on Next.js 16.4.2, the page's ownopenGraph.imageswon over a file in the same folder; a page with no image in its metadata got the file. Don't depend on either. Keep one source per route and check the output. (opengraph-image docs, read 2026-10-21.) - Server Components only.
generateMetadatadoes not run in a"use client"file. Keeppage.tsxa Server Component.
Check it
Open view-source on the deployed page and search for og:image. Paste the image URL in a new tab: it should load a 1200×630 card. Or paste the page URL in the Social preview generator. Try your title in the preview first; it is free and stamped PREVIEW. The hosted /og/ URL needs your site key: 7-day trial, then $39/mo.
Astro
Build the CardURL URL in the layout that writes your <head>, from the title each page passes in. One URL per page.
// src/cardurl.ts
const SITE_KEY = "YOUR_SITE_KEY";
export function cardUrl(
template: "blog" | "launch" | "changelog" | "docs",
params: Record<string, string>,
) {
const query = new URLSearchParams(params).toString();
return `https://cardurl.dev/og/${SITE_KEY}/${template}?${query}`;
}
---
// src/layouts/BaseLayout.astro
import { cardUrl } from "../cardurl";
interface Props {
title: string;
description: string;
date?: string;
}
const { title, description, date } = Astro.props;
const image = cardUrl("blog", {
title,
...(date ? { date } : {}),
site: "yoursite.com",
});
---
<html lang="en">
<head>
<meta charset="utf-8" />
<title>{title}</title>
<meta name="description" content={description} />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={image} />
<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={image} />
</head>
<body>
<slot />
</body>
</html>
From an .astro page: <BaseLayout title="Ship it: notes & lessons" description="A post on your site." date="Oct 24, 2026">.
Markdown pages in src/pages/ pick a layout with layout: in frontmatter, and that layout gets the frontmatter as a frontmatter prop, not as title. A small wrapper passes it on (Astro docs: Layouts, read 2026-10-24):
---
// src/layouts/PostLayout.astro
import BaseLayout from "./BaseLayout.astro";
const { frontmatter } = Astro.props;
---
<BaseLayout
title={frontmatter.title}
description={frontmatter.description}
date={frontmatter.date}
>
<article>
<h1>{frontmatter.title}</h1>
<slot />
</article>
</BaseLayout>
---
# src/pages/blog/ship-it.md
layout: ../../layouts/PostLayout.astro
title: "Ship it: notes & lessons"
description: "A post on your site."
date: "Oct 24, 2026"
---
With Astro 7.4.2, astro build wrote this to both pages:
<meta property="og:image" content="https://cardurl.dev/og/YOUR_SITE_KEY/blog?title=Ship+it%3A+notes+%26+lessons&date=Oct+24%2C+2026&site=yoursite.com">
The URL is already absolute, so you don't need Astro's site setting for it.
Eleventy
Add a filter that turns a title into the CardURL URL, then call it in the layout your posts use. Each post's front matter title becomes its own card.
// eleventy.config.js
const SITE_KEY = "YOUR_SITE_KEY";
export default function (eleventyConfig) {
eleventyConfig.addFilter("cardUrl", function (title, template = "blog") {
const params = { title, site: "yoursite.com" };
if (this.page.date) {
params.date = this.page.date.toLocaleDateString("en-US", {
month: "short", day: "numeric", year: "numeric", timeZone: "UTC",
});
}
const query = new URLSearchParams(params).toString();
return `https://cardurl.dev/og/${SITE_KEY}/${template}?${query}`;
});
}
{# _includes/base.njk #}
{% set image = title | cardUrl("blog") %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{ title }}</title>
<meta name="description" content="{{ description }}">
<meta property="og:title" content="{{ title }}">
<meta property="og:description" content="{{ description }}">
<meta property="og:image" content="{{ image }}">
<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="{{ image }}">
</head>
<body>
{{ content | safe }}
</body>
</html>
---
# blog/ship-it.md
layout: base.njk
title: "Ship it: notes & lessons"
description: "A post on your site."
date: 2026-10-24
---
With Eleventy 3.1.7 that built:
<meta property="og:image" content="https://cardurl.dev/og/YOUR_SITE_KEY/blog?title=Ship+it%3A+notes+%26+lessons&site=yoursite.com&date=Oct+24%2C+2026">
- Use
function, not an arrow.this.pageis only there in a regular function (Eleventy docs: Filters, read 2026-10-24). - Set
dateon every post. Without it, Eleventy looks for a date in the file path, then uses the file's creation date, which can change on a build server. In our test, a post with no date got the day we created the file. Drop the date block from the filter if you'd rather show none (Eleventy docs: Content Dates, read 2026-10-24). - Format in UTC.
date: 2026-10-24means midnight UTC, so formatting in a US time zone shows the day before. That's why the filter passestimeZone: "UTC"(same page).
Hugo
Put the tags in a partial and call it from the <head> of your base template. Hugo's querify builds the query string from a map, so each page's title is encoded for you (Hugo docs: querify, read 2026-10-25).
# hugo.toml
baseURL = 'https://yoursite.com/'
[params]
cardurlSiteKey = 'YOUR_SITE_KEY'
{{/* layouts/_partials/cardurl.html */}}
{{- $params := dict "title" .Title "site" "yoursite.com" -}}
{{- if and .IsPage (not .Date.IsZero) -}}
{{- $params = merge $params (dict "date" (.Date.Format "Jan 2, 2006")) -}}
{{- end -}}
{{- $image := printf "https://cardurl.dev/og/%s/blog?%s" site.Params.cardurlSiteKey (querify $params) -}}
<meta property="og:title" content="{{ .Title }}">
<meta property="og:description" content="{{ .Description }}">
<meta property="og:image" content="{{ $image }}">
<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="{{ $image }}">
{{/* layouts/baseof.html, inside <head> */}}
{{ partial "cardurl.html" . }}
---
# content/blog/ship-it.md
title: "Ship it: notes & lessons"
description: "A post on your site."
date: 2026-10-24
---
With Hugo v0.168.0 that built:
<meta property="og:image" content="https://cardurl.dev/og/YOUR_SITE_KEY/blog?date=Oct+24%2C+2026&site=yoursite.com&title=Ship+it%3A+notes+%26+lessons">
+is a plus sign. Hugo escapes+inside attributes, and crawlers read it back as+.querifyalso sorts the keys, sodatecomes first. The order doesn't change the card.- Hugo before v0.146.0 keeps partials in
layouts/partials/, notlayouts/_partials/(Hugo docs: new template system, read 2026-10-25). - Check your theme for Hugo's built-in tags. If it calls
{{ partial "opengraph.html" . }}or{{ partial "twitter_cards.html" . }}, those add their own image tags fromimagesfront matter, a page file named likefeature,coverorthumbnail, orparams.images(Hugo docs: embedded partials, read 2026-10-25). In our build, with no image set,twitter_cards.htmladded a secondtwitter:cardset tosummary; withimagesset, each page had twoog:imagetags. Remove those calls, or copy them intolayouts/_partials/without the image lines, so each page has one card.
Jekyll
Put the tags in an include and call it from the <head> of your default layout. Build the URL with cgi_escape, which turns spaces into + and encodes &, so a title can't break the query string (Jekyll docs: Liquid filters, read 2026-10-25).
# _config.yml
url: "https://yoursite.com"
cardurl_site_key: "YOUR_SITE_KEY"
{% comment %} _includes/cardurl.html {% endcomment %}
{%- capture image -%}
https://cardurl.dev/og/{{ site.cardurl_site_key }}/blog?title={{ page.title | cgi_escape }}&site=yoursite.com
{%- if page.date -%}&date={{ page.date | date: "%b %-d, %Y" | cgi_escape }}{%- endif -%}
{%- endcapture -%}
<meta property="og:title" content="{{ page.title | escape }}">
<meta property="og:description" content="{{ page.description | escape }}">
<meta property="og:image" content="{{ image | escape }}">
<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="{{ image | escape }}">
{% comment %} _layouts/default.html, inside <head> {% endcomment %}
{% include cardurl.html %}
---
# _posts/2026-10-24-ship-it.md
layout: default
title: "Ship it: notes & lessons"
description: "A post on your site."
---
With Jekyll 4.4.1 that built:
<meta property="og:image" content="https://cardurl.dev/og/YOUR_SITE_KEY/blog?title=Ship+it%3A+notes+%26+lessons&site=yoursite.com&date=Oct+24%2C+2026">
- Use
cgi_escape, noturi_escape.uri_escapeleaves reserved characters alone, sonotes & lessonsbecomesnotes%20&%20lessonsand the&ends the title early (same page). - The date comes from the post's file name, unless
datein front matter overrides it (Jekyll docs: Front Matter, read 2026-10-25). Pages without a date, likeabout.md, get a card with no date. - Using jekyll-seo-tag? In our build with version 2.9.1,
{% seo %}added a secondtwitter:cardset tosummarywhen the page had noimage, and a secondog:imagewhen it did. Check your built HTML and keep one source of image tags per page.
SvelteKit
Return each page's title from its load function, then write the tags once, in the root layout's <svelte:head>, from page.data. That's the pattern the SvelteKit docs suggest, and with SSR on (the default) the tags are in the HTML the server sends (SvelteKit docs: SEO, read 2026-10-28).
<script lang="ts">
// src/routes/+layout.svelte
import { page } from "$app/state";
let { children } = $props();
const SITE_KEY = "YOUR_SITE_KEY";
const image = $derived.by(() => {
if (!page.data.title) return null;
const query = new URLSearchParams({
title: page.data.title,
...(page.data.date ? { date: page.data.date } : {}),
site: "yoursite.com",
}).toString();
return `https://cardurl.dev/og/${SITE_KEY}/blog?${query}`;
});
</script>
<svelte:head>
{#if image}
<title>{page.data.title}</title>
<meta name="description" content={page.data.description} />
<meta property="og:title" content={page.data.title} />
<meta property="og:description" content={page.data.description} />
<meta property="og:image" content={image} />
<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={image} />
{/if}
</svelte:head>
{@render children()}
// src/routes/blog/[slug]/+page.ts
import { error } from "@sveltejs/kit";
import type { PageLoad } from "./$types";
const posts: Record<string, { title: string; description: string; date: string }> = {
"ship-it": {
title: "Ship it: notes & lessons",
description: "A post on your site.",
date: "Oct 24, 2026",
},
};
export const load: PageLoad = ({ params }) => {
const post = posts[params.slug];
if (!post) error(404, "Not found");
return post;
};
With SvelteKit 3.1.0 and Svelte 5.57.3, the server-rendered HTML for /blog/ship-it had:
<meta property="og:image" content="https://cardurl.dev/og/YOUR_SITE_KEY/blog?title=Ship+it%3A+notes+%26+lessons&date=Oct+24%2C+2026&site=yoursite.com"/>
- The
{#if}goes inside<svelte:head>.<svelte:head>has to sit at the top level of the component, never inside a block (Svelte docs: <svelte:head>, read 2026-10-28). A page whoseloadreturns notitlegets no card tags. - Keep image tags in the layout only.
<svelte:head>adds tags; it doesn't replace them. In our build, a page that also wrote its ownog:imageended up with two. - Leave SSR on for these pages. In our build, the same route with
export const ssr = falseserved HTML with noog:imageat all.
Nuxt
Call useSeoMeta in the page with the per-page CardURL URL. Pass getters (() => value) for values that come from the route or fetched data, so the tags follow the page (Nuxt docs: useSeoMeta, read 2026-10-28).
// app/utils/cardurl.ts
const SITE_KEY = "YOUR_SITE_KEY";
export function cardUrl(
template: "blog" | "launch" | "changelog" | "docs",
params: Record<string, string>,
) {
const query = new URLSearchParams(params).toString();
return `https://cardurl.dev/og/${SITE_KEY}/${template}?${query}`;
}
<script setup lang="ts">
// app/pages/blog/[slug].vue
import { cardUrl } from "~/utils/cardurl";
const posts: Record<string, { title: string; description: string; date: string }> = {
"ship-it": {
title: "Ship it: notes & lessons",
description: "A post on your site.",
date: "Oct 24, 2026",
},
};
const route = useRoute();
const post = computed(() => posts[route.params.slug as string]);
if (!post.value) {
throw createError({ statusCode: 404, statusMessage: "Not found" });
}
const image = () =>
cardUrl("blog", {
title: post.value!.title,
date: post.value!.date,
site: "yoursite.com",
});
useSeoMeta({
title: () => post.value!.title,
description: () => post.value!.description,
ogTitle: () => post.value!.title,
ogDescription: () => post.value!.description,
ogImage: image,
ogImageWidth: 1200,
ogImageHeight: 630,
twitterCard: "summary_large_image",
twitterImage: image,
});
</script>
<template>
<article>
<h1>{{ post!.title }}</h1>
</article>
</template>
With Nuxt 4.6.3, the server-rendered HTML for /blog/ship-it had:
<meta property="og:image" content="https://cardurl.dev/og/YOUR_SITE_KEY/blog?title=Ship+it%3A+notes+%26+lessons&date=Oct+24%2C+2026&site=yoursite.com">
- Nuxt writes a bare
&between the parameters, where the other examples show&. Both give crawlers the same URL. - The page's tag wins. In our build, with a site-wide
ogImagealso set inapp.vue, the page still had oneog:image: the CardURL one. - Leave SSR on for these routes. In our build, the same page under a
routeRulesentry withssr: falseserved HTML with noog:image.
React Router
Framework mode: return the post from the route's loader, then build the tags in the route's meta export from loaderData. Open Graph tags take property, not name. <Meta /> in the root <head> renders them, so with SSR on (the default) they're in the HTML the server sends (React Router docs: Meta, route module meta, <Meta />, read 2026-10-29). The helper is the same cardUrl as in the Next.js section, saved as app/cardurl.ts.
// app/routes.ts
import { type RouteConfig, route } from "@react-router/dev/routes";
export default [route("blog/:slug", "routes/post.tsx")] satisfies RouteConfig;
// app/routes/post.tsx
import { data } from "react-router";
import type { Route } from "./+types/post";
import { cardUrl } from "../cardurl";
const posts: Record<string, { title: string; description: string; date: string }> = {
"ship-it": {
title: "Ship it: notes & lessons",
description: "A post on your site.",
date: "Oct 24, 2026",
},
};
export function loader({ params }: Route.LoaderArgs) {
const post = posts[params.slug];
if (!post) throw data("Not found", { status: 404 });
return post;
}
export function meta({ loaderData }: Route.MetaArgs) {
if (!loaderData) return [{ title: "Not found" }];
const image = cardUrl("blog", {
title: loaderData.title,
date: loaderData.date,
site: "yoursite.com",
});
return [
{ title: loaderData.title },
{ name: "description", content: loaderData.description },
{ property: "og:title", content: loaderData.title },
{ property: "og:description", content: loaderData.description },
{ property: "og:image", content: image },
{ property: "og:image:width", content: "1200" },
{ property: "og:image:height", content: "630" },
{ name: "twitter:card", content: "summary_large_image" },
{ name: "twitter:image", content: image },
];
}
export default function Post({ loaderData }: Route.ComponentProps) {
return (
<article>
<h1>{loaderData.title}</h1>
</article>
);
}
// app/root.tsx
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from "react-router";
export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}
export default function App() {
return <Outlet />;
}
With React Router 7.18.5, and again with 8.5.1, the server-rendered HTML for /blog/ship-it had:
<meta property="og:image" content="https://cardurl.dev/og/YOUR_SITE_KEY/blog?title=Ship+it%3A+notes+%26+lessons&date=Oct+24%2C+2026&site=yoursite.com"/>
- A route's
metareplaces its parent's. The last matching route'smetais used, and the whole array is replaced, not merged. In our build, with a site-wideog:imageinroot.tsx'smeta,/blog/ship-ithad oneog:image: the CardURL one. A route with nometaexport got the root's. So return the title and description from the route'smetatoo, as above. - SPA mode needs prerendering for these pages. In our build,
ssr: falsefailed with this route'sloader. Addingprerender: ["/blog/ship-it"]wrote theog:imageintobuild/client/blog/ship-it/index.html.
Gatsby
Export a Head function from each page or createPage template and build the CardURL URL there from the page's data. gatsby build writes the tags into each page's static HTML. Head needs Gatsby 4.19.0 or later (Gatsby docs: Gatsby Head API, read 2026-10-29). The helper is the same cardUrl as in the Astro section, saved as src/cardurl.ts.
// gatsby-node.ts
import path from "path";
import type { GatsbyNode } from "gatsby";
const posts = [
{
slug: "ship-it",
title: "Ship it: notes & lessons",
description: "A post on your site.",
date: "Oct 24, 2026",
},
];
export const createPages: GatsbyNode["createPages"] = async ({ actions }) => {
for (const post of posts) {
actions.createPage({
path: `/blog/${post.slug}/`,
component: path.resolve("./src/templates/post.tsx"),
context: post,
});
}
};
// src/templates/post.tsx
import * as React from "react";
import type { HeadProps, PageProps } from "gatsby";
import { cardUrl } from "../cardurl";
type Post = { title: string; description: string; date: string };
export default function PostPage({ pageContext }: PageProps<object, Post>) {
return (
<article>
<h1>{pageContext.title}</h1>
</article>
);
}
export function Head({ pageContext }: HeadProps<object, Post>) {
const image = cardUrl("blog", {
title: pageContext.title,
date: pageContext.date,
site: "yoursite.com",
});
return (
<>
<title>{pageContext.title}</title>
<meta name="description" content={pageContext.description} />
<meta property="og:title" content={pageContext.title} />
<meta property="og:description" content={pageContext.description} />
<meta property="og:image" content={image} />
<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={image} />
</>
);
}
With Gatsby 5.16.1, gatsby build wrote this to public/blog/ship-it/index.html:
<meta property="og:image" content="https://cardurl.dev/og/YOUR_SITE_KEY/blog?title=Ship+it%3A+notes+%26+lessons&date=Oct+24%2C+2026&site=yoursite.com" data-gatsby-head="true"/>
- Pages and templates only.
Headworks in a page or acreatePagetemplate, not in a component, and each page defines its own tags. In our build, the home page, which has noHead, had noog:image. - Two
og:imagetags unless they share anid. In our build, aHeadthat wrote a site-wideog:imageas well as the CardURL one put both in the HTML. With the sameid="og-image"on both, only the last one was rendered, as the docs describe. - Posts from GraphQL?
Headalso gets the page query'sdata, so build the URL fromdatainstead ofpageContext.
Check it
Build, open the page's HTML and find og:image. The & is normal HTML escaping; crawlers read &. Try your title in the preview first; it's free and stamped PREVIEW. The hosted /og/ URL needs your site key: 7-day trial, then $39/mo. Params per template: templates.
WordPress
There is no CardURL WordPress plugin. You can paste each post's CardURL URL into your SEO plugin by hand, or add a small filter so Yoast SEO or Rank Math prints it for every post.
By hand
In Yoast or Rank Math, open the post → Social → Image URL, and paste that post's CardURL URL. Repeat per post or page.
Yoast / Rank Math → Social → Image URL https://cardurl.dev/og/YOUR_SITE_KEY/blog?title=Ship+it
With a filter
Both plugins document a filter for the image URL they print. Yoast: wpseo_opengraph_image and wpseo_twitter_image (Yoast Metadata API). Rank Math: rank_math/opengraph/{$network}/image, where the network is facebook or twitter (Rank Math OpenGraph filters). Both read 2026-10-26. Save this as wp-content/mu-plugins/cardurl.php (a must-use plugin). It changes single posts only; pages and archives keep the image the plugin already picks.
<?php
/**
* Plugin Name: CardURL og:image
* Description: Point the SEO plugin's og:image at a per-post CardURL URL.
*/
const CARDURL_SITE_KEY = 'YOUR_SITE_KEY';
function cardurl_image_url( $post_id ) {
$params = array(
'title' => html_entity_decode( get_post_field( 'post_title', $post_id, 'raw' ), ENT_QUOTES, 'UTF-8' ),
'date' => get_the_date( 'M j, Y', $post_id ),
'site' => 'yoursite.com',
);
return 'https://cardurl.dev/og/' . CARDURL_SITE_KEY . '/blog?' . http_build_query( $params );
}
function cardurl_filter_image( $url ) {
return is_singular( 'post' ) ? cardurl_image_url( get_queried_object_id() ) : $url;
}
// Yoast SEO
add_filter( 'wpseo_opengraph_image', 'cardurl_filter_image' );
add_filter( 'wpseo_twitter_image', 'cardurl_filter_image' );
// Rank Math
add_filter( 'rank_math/opengraph/facebook/image', 'cardurl_filter_image' );
add_filter( 'rank_math/opengraph/twitter/image', 'cardurl_filter_image' );
What a post titled "Ship it: notes & lessons" printed with Yoast SEO 28.7 and with Rank Math 1.0.280 (same two lines from both):
<meta property="og:image" content="https://cardurl.dev/og/YOUR_SITE_KEY/blog?title=Ship+it%3A+notes+%26+lessons&date=Oct+24%2C+2026&site=yoursite.com" />
<meta name="twitter:image" content="https://cardurl.dev/og/YOUR_SITE_KEY/blog?title=Ship+it%3A+notes+%26+lessons&date=Oct+24%2C+2026&site=yoursite.com" />
- Yoast only replaces an image that already exists (Yoast docs). A post with no featured image and no Site image printed no og:image at all, only twitter:image. Set a Site image (Yoast SEO → Settings → Site basics) so every post has one to replace.
- Yoast keeps the width, height and type of the image it replaced. With an 800×800 featured image, og:image:width and og:image:height stayed 800, not the card's 1200×630.
- Rank Math printed the card with or without a featured image, and printed no og:image:width or height.
- Keep
html_entity_decode. WordPress can store an&in a title as&, and without it the card would read "&". - Rank Math suggests putting its filters in your theme's
rank-math.phpso they only load with the plugin (Rank Math docs). The must-use plugin above works with either plugin.
More: Getting started.
Demonstration cards
Sample titles for the four templates. Not customer work.