OG Pilot
WordPress guide

How to add OG Pilot social images to WordPress

Give every WordPress post a scroll-stopping Open Graph preview. This guide shows how to connect OG Pilot to your theme so each share pulls the right branded image automatically.

What you need

Before you start

  • An active OG Pilot subscription with your WordPress domain verified.
  • An API key created for that domain (you will use it to sign JWT tokens).
  • Administrator access to the WordPress site you want to update.
  • A recent backup of functions.php in case you need to undo changes quickly.

Time to complete

About 10 minutes

The update applies instantly once the file is saved. Some social platforms may cache the previous image until you force a re-scrape.

WordPress integration steps

Follow this proven workflow to insert custom Open Graph and Twitter Card meta tags powered by OG Pilot directly into your theme.

1

Create an API key and verify your domain

In OG Pilot, add your WordPress domain and complete DNS verification, then generate an API key for that domain.

2

Store the API key safely

Add the API key to wp-config.php as a constant so your theme can sign JWTs without exposing secrets in the editor.

3

Paste the JWT helper

Open functions.php in your active theme and add the OG Pilot helper function. It builds a signed JWT payload using your post data and calls the new API endpoint.

4

Save and verify the tags

Click Update File, view the page source, and confirm the new og:image and twitter:image tags appear on single posts and pages.

5

Refresh social caches

Use the Facebook Sharing Debugger and X (Twitter) Card Validator to trigger a fresh scrape so platforms pick up your new OG Pilot image immediately.

You are done! Future OG Pilot images will populate automatically whenever a post or page is shared.

Copy & paste helper

Drop this snippet into functions.php

This helper builds a signed JWT payload from WordPress data (title, excerpt, featured image, and optional author metadata) and calls the new /api/v1/images endpoint. OG Pilot uses those fields to render a branded social image for every post and page.

// Define OG_PILOT_API_KEY in wp-config.php for production.
// define('OG_PILOT_API_KEY', 'YOUR_API_KEY');

function og_pilot_base64url_encode($data) {
    return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}

function og_pilot_build_jwt($payload, $secret) {
    $header = ['typ' => 'JWT', 'alg' => 'HS256'];
    $segments = [];
    $segments[] = og_pilot_base64url_encode(json_encode($header));
    $segments[] = og_pilot_base64url_encode(json_encode($payload));
    $signing_input = implode('.', $segments);
    $signature = hash_hmac('sha256', $signing_input, $secret, true);
    $segments[] = og_pilot_base64url_encode($signature);
    return implode('.', $segments);
}

function og_pilot_add_og_tags() {
    if (!is_single() && !is_page()) {
        return;
    }
    if (!defined('OG_PILOT_API_KEY') || !OG_PILOT_API_KEY) {
        return;
    }

    $domain = parse_url(home_url(), PHP_URL_HOST);
    $path = parse_url(get_permalink(), PHP_URL_PATH);
    $title = get_the_title();
    $description = wp_strip_all_tags(get_the_excerpt());
    $image_url = get_the_post_thumbnail_url(null, 'full');
    $logo_url = get_site_icon_url(512);
    $author_avatar_url = is_single() ? get_avatar_url(get_the_author_meta('ID')) : null;

    $payload = array_filter([
        'iss' => $domain,
        'sub' => substr(OG_PILOT_API_KEY, 0, 8),
        'iat' => time(),
        'template' => is_single() ? 'blog_post' : 'page',
        'title' => $title,
        'description' => $description,
        'logo_url' => $logo_url,
        'image_url' => $image_url,
        'author_name' => is_single() ? get_the_author() : null,
        'author_avatar_url' => $author_avatar_url,
        'publish_date' => is_single() ? get_the_date('Y-m-d') : null,
        'path' => $path,
    ]);

    $token = og_pilot_build_jwt($payload, OG_PILOT_API_KEY);
    $og_image_url = 'https://ogpilot.com/api/v1/images?' . http_build_query(['token' => $token]);

    echo '<meta property="og:image" content="' . esc_url($og_image_url) . '" />' . "\n";
    echo '<meta property="og:image:width" content="1200" />' . "\n";
    echo '<meta property="og:image:height" content="630" />' . "\n";
    echo '<meta property="og:image:type" content="image/png" />' . "\n";
    echo '<meta name="twitter:card" content="summary_large_image" />' . "\n";
    echo '<meta name="twitter:image" content="' . esc_url($og_image_url) . '" />' . "\n";
}

add_action('wp_head', 'og_pilot_add_og_tags');

Keep your WordPress previews on-brand

Create unlimited variations with OG Pilot so your headlines, product shots, and campaigns always look fresh across Facebook, LinkedIn, X, and more.

Generate new images

Pro tip

OG Pilot will automatically use your configured domain settings and templates to generate a polished preview for every page, ensuring consistent branding across all your WordPress content.