20. OG and Twitter Cards | SEO Forge - Rank Higher with AI-Powered SEO
Download Log in

20. OG and Twitter Cards

Developer Guide

SEO Forge outputs Open Graph and Twitter Card meta tags on singular pages via SEOFORGE_Meta_Generator.

Output (Priority 1 on wp_head)

html
<meta property="og:type" content="article">
<meta property="og:title" content="Post Title | Site Name">
<meta property="og:description" content="Meta description text...">
<meta property="og:url" content="https://example.com/my-post/">
<meta property="og:site_name" content="Site Name">
<meta property="og:image" content="https://example.com/featured-image.jpg">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Post Title | Site Name">
<meta name="twitter:description" content="Meta description text...">
<meta name="twitter:image" content="https://example.com/featured-image.jpg">

OG Image Cascade

  1. Per-post social image attachment (_seoforge_og_image_id)
  2. Stored social image URL (_seoforge_og_image) when the attachment ID is stale
  3. Post featured image (get_the_post_thumbnail_url( $post_id, 'large' ))
  4. WooCommerce placeholder image for product pages without product imagery
  5. Default OG image (seoforge_default_og_image option)

Setting the Default OG Image

php
update_option( 'seoforge_default_og_image', 'https://example.com/default-social-1200x630.jpg' );

Adding Additional OG Tags

php
add_action( 'wp_head', function () {
    if ( ! is_singular() ) {
        return;
    }

    $thumb_id = get_post_thumbnail_id();
    if ( $thumb_id ) {
        $meta = wp_get_attachment_metadata( $thumb_id );
        if ( $meta ) {
            echo '<meta property="og:image:width" content="' . esc_attr( $meta['width'] ) . '">' . "n";
            echo '<meta property="og:image:height" content="' . esc_attr( $meta['height'] ) . '">' . "n";
        }
    }

    // Add Twitter site handle
    echo '<meta name="twitter:site" content="@mywebsite">' . "n";
}, 2 );

Forge AI Assistant Online

Hi! I'm the SEO Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs