OG Images for WordPress
Dynamic OG images for WordPress — no plugin bloat
Add beautiful Open Graph images to your WordPress site without installing heavy SEO plugins. OGMagic generates images via URL — just add a snippet to your theme.
Quick Start
Add OGMagic to your WordPress project — no packages to install, no API keys to configure.
<?php
// functions.php — Add OGMagic OG images to all pages
add_action('wp_head', function() {
$title = is_singular() ? get_the_title() : get_bloginfo('name');
$desc = is_singular() ? wp_trim_words(get_the_excerpt(), 20) : get_bloginfo('description');
$domain = parse_url(home_url(), PHP_URL_HOST);
$og_url = 'https://ogmagic.dev/api/og?' . http_build_query([
'template' => 'gradient-mesh',
'title' => $title,
'description' => $desc,
'domain' => $domain,
]);
?>
<meta property="og:image" content="<?php echo esc_url($og_url); ?>" />
<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="<?php echo esc_url($og_url); ?>" />
<?php
});Dynamic OG Images
Generate unique OG images per page using route data:
<?php
// For Yoast SEO users — override the OG image with OGMagic
add_filter('wpseo_opengraph_image', function($image) {
if (is_singular()) {
return 'https://ogmagic.dev/api/og?' . http_build_query([
'template' => 'gradient-mesh',
'title' => get_the_title(),
'description' => wp_trim_words(get_the_excerpt(), 20),
'domain' => parse_url(home_url(), PHP_URL_HOST),
]);
}
return $image;
});
// For Rank Math users
add_filter('rank_math/opengraph/facebook/image', function($image) {
if (is_singular()) {
return 'https://ogmagic.dev/api/og?' . http_build_query([
'template' => 'gradient-mesh',
'title' => get_the_title(),
'domain' => parse_url(home_url(), PHP_URL_HOST),
]);
}
return $image;
});💡 Works with any WordPress theme. Compatible with Yoast SEO, Rank Math, and All in One SEO via their filter hooks. No plugin installation needed.
Why use OGMagic with WordPress?
No build step
Images are generated on-demand via URL. No build plugins, no CI/CD changes.
55+ templates
Professional designs out of the box. Customize with query parameters.
No API key needed
Free tier works instantly — just use the URL. No signup, no config.
Every platform
Optimized 1200×630 images that look great on Twitter/X, Facebook, LinkedIn, Discord, and Slack.
Ready to add OG images to your WordPress app?
Start with 50 free API calls/month. No signup needed.