Overview
The GeoAI_Social class manages social media meta tags (OpenGraph and Twitter Cards) to control how your content appears when shared on social platforms like Facebook, Twitter, LinkedIn, and others.
Namespace: GeoAI\Core
Location: includes/class-geoai-social.php
Key Features
- OpenGraph meta tags
- Twitter Card meta tags
- Custom social images
- Per-post social overrides
- Automatic fallback to defaults
- Compatibility mode support
Public Methods
get_instance()
Returns the singleton instance of the social class.
public static function get_instance()
Returns: GeoAI_Social - The singleton instance
Example:
$social = \GeoAI\Core\GeoAI_Social::get_instance();
Outputs OpenGraph and Twitter Card meta tags in the website head.
public function output_og_tags()
Hooks: wp_head (priority 1)
Outputs:
- OpenGraph meta tags (og:*)
- Twitter Card meta tags (twitter:*)
Example Output:
<meta property="og:type" content="article" />
<meta property="og:title" content="Post Title" />
<meta property="og:description" content="Post description..." />
<meta property="og:url" content="https://example.com/post/" />
<meta property="og:image" content="https://example.com/image.jpg" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="Post Title" />
<meta name="twitter:description" content="Post description..." />
<meta name="twitter:image" content="https://example.com/image.jpg" />
<meta name="twitter:site" content="@yoursite" />
Supported Properties
Content type (always “article” for posts)
Post title or custom override
Post excerpt or custom description
Canonical URL of the post
Featured image, custom image, or default fallback
Image Fallback Priority
- Custom post override image
- Post featured image
- Default site-wide image from settings
Supported Properties
Card type: “summary” or “summary_large_image”
Twitter handle for the site (e.g., @yoursite)
Card Types
summary - Small square image
summary_large_image - Large rectangular image (recommended)
Configuration
Global Defaults
Set default social media settings:
$defaults = array(
'og_image' => 'https://example.com/default-og-image.jpg',
'og_image_id' => 123, // WordPress attachment ID
'tw_card' => 'summary_large_image',
'tw_site' => '@yoursite'
);
update_option( 'geoai_social_defaults', $defaults );
Settings Reference
Default OpenGraph image URL
WordPress attachment ID for default image
tw_card
string
default:"summary_large_image"
Twitter Card type
Twitter handle with @ symbol
Per-Post Overrides
Override social meta for individual posts:
$post_id = 123;
$overrides = array(
'og_title' => 'Custom Social Title',
'og_desc' => 'Custom social description for sharing',
'og_image' => 'https://example.com/custom-social-image.jpg'
);
update_post_meta( $post_id, '_geoai_social_overrides', $overrides );
Override Fields
Custom title for social sharing (overrides post title)
Custom description for social sharing (overrides excerpt)
Custom image URL for social sharing (overrides featured image)
Usage Examples
Set Default Social Image
// Upload or get existing image
$image_id = 123; // WordPress attachment ID
$image_url = wp_get_attachment_url( $image_id );
$defaults = get_option( 'geoai_social_defaults', array() );
$defaults['og_image'] = $image_url;
$defaults['og_image_id'] = $image_id;
update_option( 'geoai_social_defaults', $defaults );
$defaults = get_option( 'geoai_social_defaults', array() );
$defaults['tw_card'] = 'summary_large_image';
$defaults['tw_site'] = '@mywebsite';
update_option( 'geoai_social_defaults', $defaults );
Custom Social Meta for Post
$post_id = get_the_ID();
update_post_meta( $post_id, '_geoai_social_overrides', array(
'og_title' => 'Amazing Article - Must Read!',
'og_desc' => 'Discover the secrets to success in this comprehensive guide.',
'og_image' => 'https://example.com/special-share-image.jpg'
));
Get Social Meta for Post
$post_id = 123;
$overrides = get_post_meta( $post_id, '_geoai_social_overrides', true );
$defaults = get_option( 'geoai_social_defaults', array() );
// Determine final values
$og_title = $overrides['og_title'] ?? get_the_title( $post_id );
$og_image = $overrides['og_image'] ??
get_the_post_thumbnail_url( $post_id, 'large' ) ?:
$defaults['og_image'] ?? '';
Image Requirements
OpenGraph Image Specs
1200 x 630 pixels (1.91:1 ratio)
JPG or PNG (avoid WebP for compatibility)
Under 8MB, preferably under 1MB
Include text overlay with brand or key message
Summary Card: 1:1 ratio, minimum 144x144px
Summary Large Image: 2:1 ratio, minimum 300x157px, recommended 1200x600px
Facebook Sharing Debugger
Test and clear cache:
https://developers.facebook.com/tools/debug/
Enter your URL and click “Scrape Again” to refresh Facebook’s cache.
Validate Twitter Cards:
https://cards-dev.twitter.com/validator
LinkedIn Post Inspector
Test LinkedIn sharing:
https://www.linkedin.com/post-inspector/
Compatibility Mode
The class respects compatibility settings:
if ( ! GeoAI_Compat::get_instance()->should_output_meta() ) {
return; // Skip output when in coexist mode
}
This prevents duplicate social meta tags when using other SEO plugins.
Fallback Behavior
Title Fallback
- Custom og_title override
- Post title
Description Fallback
- Custom og_desc override
- Post excerpt (trimmed to 30 words)
Image Fallback
- Custom og_image override
- Post featured image (large size)
- Default site-wide og_image from settings
- Empty (no image tag output)
Advanced Customization
Add Additional OpenGraph Properties
add_action( 'wp_head', function() {
if ( is_singular( 'post' ) ) {
$post = get_post();
echo '<meta property="og:published_time" content="' .
esc_attr( get_the_date( 'c', $post ) ) . '" />' . "\n";
echo '<meta property="og:modified_time" content="' .
esc_attr( get_the_modified_date( 'c', $post ) ) . '" />' . "\n";
$category = get_the_category( $post );
if ( ! empty( $category ) ) {
echo '<meta property="article:section" content="' .
esc_attr( $category[0]->name ) . '" />' . "\n";
}
}
}, 2 );
add_action( 'wp_head', function() {
if ( is_singular() ) {
$author_twitter = get_the_author_meta( 'twitter' );
if ( $author_twitter ) {
echo '<meta name="twitter:creator" content="@' .
esc_attr( $author_twitter ) . '" />' . "\n";
}
}
}, 2 );