Support Log in

20. OG and Twitter Cards

Developer Guide
Prefer video? Watch the Rank Forge tutorials 9 short guides covering every feature Watch

Rank Forge outputs Open Graph and Twitter Card meta tags via RANKFORGE_Meta_Generator on single posts and pages, the home page, term and post type archives, author and date archives, and search and 404 pages. Attachment pages and feeds get none. Of the Twitter tags, Rank Forge writes twitter:card, twitter:title, twitter:description and twitter:image, not twitter:site or twitter:creator; the example under Adding Additional OG Tags adds twitter:site by hand.

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 (_rankforge_og_image_id)
  2. Stored social image URL (_rankforge_og_image) when the attachment ID is stale
  3. Post featured image (get_the_post_thumbnail_url( $post_id, 'full' ))
  4. WooCommerce placeholder image for product pages without product imagery
  5. Default OG image (rankforge_default_og_image option)

Setting the Default OG Image

php
update_option( 'rankforge_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 Rank Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs