OG images for every WordPress post
One snippet in your theme's functions.php. Every post and page gets its own link preview on X, LinkedIn, WhatsApp and Slack.
Make your preview
Paste your site, pick one of three designs and publish it. Then open Add to site → WordPress.
Add the snippet
Paste it at the end of your theme's functions.php (a child theme is best). If you'd rather not edit theme files, a code snippets plugin such as Code Snippets or WPCode works too.
// functions.php — getwowlink link previews
if (!function_exists('getwowlink_image')) {
function getwowlink_image() {
global $wp;
$path = trim((string) wp_parse_url(home_url($wp->request), PHP_URL_PATH), '/');
return 'https://getwowimg.com/a1b2c3d4e5/' . ($path === '' ? 'index' : $path) . '.png';
}
add_action('init', function () {
if (defined('WPSEO_VERSION') && class_exists('WPSEO_Options') && WPSEO_Options::get('opengraph')) {
add_filter('wpseo_add_opengraph_additional_images', function ($images) {
if (!$images->has_images()) {
$images->add_image(getwowlink_image());
}
return $images;
});
add_filter('wpseo_opengraph_image', 'getwowlink_image');
add_filter('wpseo_opengraph_image_width', function () { return 1200; });
add_filter('wpseo_opengraph_image_height', function () { return 630; });
add_filter('wpseo_opengraph_image_type', function () { return 'image/png'; });
add_filter('wpseo_twitter_image', 'getwowlink_image');
return;
}
if (class_exists('RankMath')) {
add_filter('rank_math/opengraph/facebook/image', 'getwowlink_image');
add_filter('rank_math/opengraph/twitter/image', 'getwowlink_image');
return;
}
if (defined('WPSEO_VERSION')) {
add_filter('wpseo_twitter_image', '__return_empty_string');
}
add_action('wp_head', function () {
$image = esc_attr(getwowlink_image());
echo '<meta property="og:image" content="' . $image . '" />' . "\n";
echo '<meta property="og:image:width" content="1200" />' . "\n";
echo '<meta property="og:image:height" content="630" />' . "\n";
echo '<meta name="twitter:card" content="summary_large_image" />' . "\n";
echo '<meta name="twitter:image" content="' . $image . '" />' . "\n";
});
});
}a1b2c3d4e5 is a sample site ID — Add to site gives you the code with yours.That’s it — every post has its image
With Yoast SEO or Rank Math the image goes through their own filters, so there are no duplicate tags. Edit a post and its image updates a minute later.
Open the OG checkerWorks with your SEO plugin
With Yoast SEO or Rank Math active, the snippet hands the image to them through their own filters — no duplicate tags. No SEO plugin? It adds the tags itself.
Before and after
Questions
Do I need a plugin?
No. One snippet does it; a code-snippets plugin is the easiest place to paste it if you don't edit theme files.
Will it slow my site down?
No. Images are served from our CDN; the snippet only adds a tag.
Does it work with my SEO plugin?
With Yoast SEO or Rank Math active, the snippet hands the image to them through their own filters — no duplicate tags. No SEO plugin? It adds the tags itself.
I use another SEO plugin.
Turn off its Open Graph image (All in One SEO, SEOPress and others have a setting for it), and the snippet adds the tags itself.
Try it on your site
Three designs made from your site — no sign-up to try.