API Reference
This document provides technical details about the Open Graph Meta Generator tool and its underlying functionality.
Tool Overview
The Open Graph Meta Generator is a client-side tool that generates HTML meta tags for Open Graph and Twitter Card protocols. It processes user input and outputs properly formatted HTML meta tags.
Input Parameters
General Information
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
pageType | string | Yes | Content type | "website" , "article" , "book" |
title | string | No | Page title | "My Awesome Website" |
description | string | No | Page description | "A great website for developers" |
url | string | No | Page URL | "https://example.com/page" |
siteName | string | No | Site name | "My Company" |
Image Settings
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
imageUrl | string | No | Image URL | "https://example.com/image.jpg" |
imageAlt | string | No | Image alt text | "Company logo" |
imageWidth | string | No | Image width in pixels | "1200" |
imageHeight | string | No | Image height in pixels | "630" |
Twitter Settings
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
twitterCardType | string | Yes | Twitter card type | "summary_large_image" |
twitterSite | string | No | Site Twitter handle | "@example" |
twitterCreator | string | No | Creator Twitter handle | "@author" |
Output Format
The tool generates HTML meta tags in the following format:
Open Graph Tags
<!-- Open Graph Meta Tags -->
<meta property="og:type" content="website" />
<meta property="og:title" content="Page Title" />
<meta property="og:description" content="Page description" />
<meta property="og:url" content="https://example.com/page" />
<meta property="og:site_name" content="Site Name" />
<meta property="og:image" content="https://example.com/image.jpg" />
<meta property="og:image:alt" content="Image description" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
Twitter Tags
<!-- Twitter Meta Tags -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@example" />
<meta name="twitter:creator" content="@author" />
<meta name="twitter:title" content="Page Title" />
<meta name="twitter:description" content="Page description" />
<meta name="twitter:image" content="https://example.com/image.jpg" />
Content Types
Supported Page Types
Type | Description | Use Case |
---|---|---|
website | General website pages | Homepage, about page, contact page |
article | Blog posts, news articles | Blog posts, news articles, tutorials |
book | Book pages, e-books | Book listings, e-book pages |
profile | Personal or business profiles | User profiles, company pages |
music | Music tracks, albums | Music streaming, album pages |
video | Video content | Video pages, movie listings |
Twitter Card Types
Type | Description | Best For |
---|---|---|
summary | Basic card with thumbnail | Blog posts, news articles |
summary_large_image | Card with large image | Visual content, products |
app | Mobile app promotion | App store pages |
player | Video/audio content | Video pages, podcasts |
Data Processing
HTML Escaping
All user input is automatically escaped to prevent XSS attacks:
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
URL Validation
URLs are validated to ensure they are properly formatted:
function isValidUrl(string) {
try {
new URL(string);
return true;
} catch (_) {
return false;
}
}
Content Length Limits
The tool enforces recommended length limits:
- Title: 60 characters maximum
- Description: 160 characters maximum
- URL: Must be valid URL format
Browser Compatibility
Supported Browsers
Browser | Version | Support |
---|---|---|
Chrome | 60+ | Full support |
Firefox | 55+ | Full support |
Safari | 12+ | Full support |
Edge | 79+ | Full support |
Required Features
- ES6+ support
- Clipboard API support
- Local Storage support
- CSS Grid support
Performance Considerations
Client-Side Processing
- All processing happens in the browser
- No server requests required
- Instant generation and preview
- Minimal memory footprint
Caching
- Generated meta tags are cached in browser storage
- History records are stored locally
- No external dependencies
Error Handling
Input Validation Errors
// Example error handling
if (!title.trim()) {
showError('Title is required');
return;
}
if (url && !isValidUrl(url)) {
showError('Please enter a valid URL');
return;
}
Image Loading Errors
// Handle image loading errors
function handleImageError(event) {
const img = event.target;
img.style.display = 'none';
showWarning('Image failed to load');
}
Integration Examples
WordPress Integration
// Add to functions.php
function add_open_graph_tags() {
if (is_single()) {
$title = get_the_title();
$description = get_the_excerpt();
$image = get_the_post_thumbnail_url();
echo '<meta property="og:title" content="' . esc_attr($title) . '" />';
echo '<meta property="og:description" content="' . esc_attr($description) . '" />';
echo '<meta property="og:image" content="' . esc_url($image) . '" />';
}
}
add_action('wp_head', 'add_open_graph_tags');
React Integration
// React component example
function OpenGraphMeta({ title, description, image, url }) {
return (
<>
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={image} />
<meta property="og:url" content={url} />
</>
);
}
Next.js Integration
// Next.js Head component
import Head from 'next/head';
function MyPage() {
return (
<Head>
<meta property="og:title" content="My Page Title" />
<meta property="og:description" content="My page description" />
<meta property="og:image" content="https://example.com/image.jpg" />
</Head>
);
}
Testing and Validation
Social Media Debuggers
- Facebook: developers.facebook.com/tools/debug
- Twitter: cards-dev.twitter.com/validator
- LinkedIn: linkedin.com/post-inspector
Automated Testing
// Example test for meta tag generation
describe('Open Graph Meta Generator', () => {
test('generates correct meta tags', () => {
const input = {
pageType: 'website',
title: 'Test Page',
description: 'Test description',
};
const output = generateMetaTags(input);
expect(output).toContain('<meta property="og:type" content="website" />');
expect(output).toContain('<meta property="og:title" content="Test Page" />');
});
});
Troubleshooting
Common Issues
- Images not displaying: Check URL format and accessibility
- Tags not working: Validate with social media debuggers
- Truncated content: Check character limits
- Cache issues: Use debugger tools to refresh cache
Debug Mode
Enable debug mode to see detailed information:
// Enable debug logging
localStorage.setItem('debug', 'true');
Future Enhancements
Planned Features
- Schema.org structured data support
- Multiple language support
- Bulk generation capabilities
- API endpoint for server-side generation
- Advanced image optimization
- Analytics integration
Contributing
To contribute to the Open Graph Meta Generator:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
Support
For technical support or questions: