When a link is shared on social media or messaging platforms, the platform's crawler scrapes the URL to generate a rich snippet. Without specific instructions, these platforms may scrape arbitrary content, often leading to missing images, truncated descriptions, and broken formatting. Open Graph (OG) tags and Twitter Card markup can help solve this issue. They provide editorial control over the headline, preview image, summary text, and routing behavior whenever your content appears in social feeds, Slack, Discord, and messaging apps.
What Are Open Graph and Twitter Card Tags?
The Open Graph Protocol, introduced by Facebook in 2010, has become the industry standard for social platforms. It uses `<meta property="og:*" content="...">` tags placed in the `<head>` section of your HTML document. Platforms like Facebook, LinkedIn, Pinterest, WhatsApp, Telegram, and Discord utilize these tags to create rich link cards. Twitter Cards (for X/Twitter) use `<meta name="twitter:*" content="...">` markup. Although Twitter can fallback on standard Open Graph tags if Twitter-specific tags are absent, defining native Twitter meta tags ensures precise control over layout formats, such as large edge-to-edge banners versus compact square-thumbnail layouts.
Core Tags & Technical Specifications
Let's explain the Open Graph and Twitter Card elements while setting them up in WordPress with Yoast or ACF.
Critical Open Graph Elements:
- og:title: The headline displayed in the preview (40–60 characters to avoid truncation). Reserve brand names for og:site_name
- og:description: A concise hook (55–150 characters) elaborating on the title
- og:image: Absolute URL to the preview image (Recommended: 1200 x 630 px, 1.91:1 aspect ratio, < 8 MB)
- og:url: The canonical URL without tracking parameters (utm_*) to consolidate engagement signals
- og:type: Schema category ("website" for static pages, "article" for blog posts)
Core Twitter Card Elements:
- twitter:card:and Specifies the card format. The most effective options are:
- twitter:card: Card format (summary_large_image for full-width banners; summary for compact horizontal thumbnails)
- twitter:site: The brand's @username
- twitter:creator: The author's @username
- twitter:title & twitter:description: Twitter-specific headline and text overrides
- twitter:image: Absolute image URL displayed in Twitter feeds
Comprehensive Code Implementation
Drop this production-ready boilerplate into the <head> section of your HTML template:
Setting Up and Configuring Open Graph Tags in WordPress Using Yoast or ACF
You can set up Open Graph (OG) and Twitter tags in WordPress using two primary approaches, depending on your technical setup:
Yoast SEO (Plugin-Based / Standard CMS)
This method is ideal if you're looking for a user-friendly interface that allows authors and editors to customize social titles, descriptions, and preview images for each post without the need for coding.
ACF (Advanced Custom Fields / Code-Based)
This approach is best suited for those using a custom theme or a headless WordPress setup, where you desire full programmatic control over custom fields, metadata output, and dynamic fallbacks.
Method 1: Using Yoast SEO (Standard / GUI Approach)
Yoast automatically generates basic Open Graph and Twitter Card tags by default, using your site's title, featured image, and excerpt. Here’s how to configure global settings and per-post overrides:
Enable Global Social Settings
- In your WordPress dashboard, go to Yoast SEO > Settings (or Social in older versions)
- Under Site Features, ensure that both Open Graph data and Twitter card data are toggled ON
- In the Social Profiles section, add your brand's social media handles (e.g., your X/Twitter @handle, Facebook Page URL, LinkedIn profile). This information populates the `twitter:site` tag and structured schema data
- In the Social Sharing section (or Content Types > Pages/Posts), upload a Default social share image (1200 x 630 px). This image will serve as a fallback if an editor publishes a post without a designated featured image
Configure Per-Post / Per-Page Metadata
When editing any post or page in the Block or Classic Editor, scroll down to the Yoast SEO meta box located below or beside the editor.
- Click on the Social tab
- Here, you will see previews for Facebook (standard Open Graph) and Twitter:
- Social Title: This overrides `og:title` and `twitter:title` if you need a title different from your SEO title
- Social Description: This overrides `og:description` and `twitter:description`
- Social Image: Upload a dedicated image (1200 x 630 px). Use this if your internal featured image has a different aspect ratio that may appear cropped on social feeds
Method 2: Programmatic Setup with Advanced Custom Fields (ACF)
If you are developing a custom WordPress theme (or want to create custom meta boxes without using a comprehensive SEO plugin), you can create specific social fields using ACF and directly inject the tags into `wp_head`.
Step 1: Create Custom Fields in ACF
- Navigate to ACF > Field Groups > Add New.
- Name the group: Social Metadata.
- Set the location rule to: Post Type is equal to Post (and/or Page).
- Add the following fields:
- Field Label: Social Title | Field Name: `og_title` | Type: Text
- Field Label: Social Description | Field Name: `og_description` | Type: Textarea
- Field Label: Social Image | Field Name: `og_image` | Type: Image (Set Return Value to Image URL)
- Field Label: Twitter Card Type | Field Name: `twitter_card_type` | Type: Select (Choices: `summary_large_image`, `summary`)
Step 2: Hook the Tags into (wp_head)
Add the following code to your active theme’s `functions.php` file (or a site-specific custom plugin). This code will pull data from ACF first, then fall back to native WordPress data (featured image, excerpt, post title) if necessary.
Method 3: Linking ACF directly into Yoast SEO Filters
If Yoast SEO is already installed and you want ACF custom fields to automatically override Yoast's output without printing duplicate tags, add these filters to functions.php:
Method 4: Headless WordPress (ACF + Next.js App Router)
Enable Show in REST API in your ACF Field Group settings. In your frontend application (e.g., Next.js 14+), map the ACF fields in generateMetadata:
Verification Note
If you are using both Yoast SEO and custom ACF code, it's important to disable Yoast's social tags by navigating to Yoast SEO > Settings. This step will help prevent duplicate `<meta property="og:*">` tags, which can cause confusion with Facebook and LinkedIn parsers.
After publishing your content, be sure to test the live link using the LinkedIn Post Inspector or Facebook Sharing Debugger. This will allow you to verify that the tags are populating correctly.
Implementation Checklist
[ ] Use absolute URLs (starting with https://) for both `og:url` and all image assets
[ ] Format visual assets to 1200 × 630 pixels with a 1.91:1 aspect ratio
[ ] Keep headlines between 40 and 60 characters to ensure visibility across devices
[ ] Keep descriptions under 150 characters, prioritizing the core value proposition at the beginning
[ ] Include `og:image:alt` and `twitter:image:alt` tags for accessibility and screen reader support
[ ] Test pages with debugging tools before scheduling distribution campaigns
Conclusion
Configuring Open Graph and Twitter Card tags in WordPress significantly affects how your content performs across social media platforms and messaging apps. Without proper metadata, link previews are left to chance, often resulting in broken thumbnails, poorly cropped logos, and arbitrary snippet text that can reduce click-through rates.
You have several options for implementing tags: use Yoast SEO for a no-code, editorial workflow; leverage ACF with custom PHP hooks for complete control at the theme level; or establish an ACF-to-REST API pipeline for modern headless architectures. Regardless of your approach, the goal remains the same:
- Deliver eye-catching imagery with dimensions of 1200 × 630 pixels, optimized for a 1.91:1 aspect ratio, suitable for feed viewports.
- Craft engaging, concise headlines (under 60 characters) that are designed for social engagement rather than just focusing on search keyword density.
- Ensure proper canonical fallback handling so that unpopulated fields never result in empty or broken preview cards.
Once your tags are implemented, remember to include cache invalidation in your publishing and debugging routine. Use tools like the LinkedIn Post Inspector and Meta Sharing Debugger to aid in this process. Fully controlling your social cards ensures that your site projects authority, enhances brand consistency, and maximizes traffic whenever your audience shares your work.

Comments
Post a Comment