apply static method
void
apply({
- required String title,
- required String description,
- required String imageUrl,
- String? url,
- String? siteName,
- String? twitterSite,
- String? twitterCreator,
- TwitterCardType twitterCardType = TwitterCardType.summaryLargeImage,
- OgType ogType = OgType.website,
- String? imageWidth,
- String? imageHeight,
- String? imageAlt,
- String? locale,
Apply social preview tags for all platforms at once.
This sets Open Graph tags (Facebook, LinkedIn, Discord, Slack) and Twitter Card tags simultaneously.
Implementation
static void apply({
required String title,
required String description,
required String imageUrl,
String? url,
String? siteName,
String? twitterSite,
String? twitterCreator,
TwitterCardType twitterCardType = TwitterCardType.summaryLargeImage,
OgType ogType = OgType.website,
String? imageWidth,
String? imageHeight,
String? imageAlt,
String? locale,
}) {
if (!Webify.isInitialized) return;
final webify = Webify.instance;
// Open Graph (Facebook, LinkedIn, Discord, Slack, etc.)
webify.platform.setPropertyMetaTag('og:title', title);
webify.platform.setPropertyMetaTag('og:description', description);
webify.platform.setPropertyMetaTag('og:image', imageUrl);
webify.platform.setPropertyMetaTag('og:type', ogType.value);
if (url != null) {
webify.platform.setPropertyMetaTag('og:url', url);
}
if (siteName != null) {
webify.platform.setPropertyMetaTag('og:site_name', siteName);
}
if (imageWidth != null) {
webify.platform.setPropertyMetaTag('og:image:width', imageWidth);
}
if (imageHeight != null) {
webify.platform.setPropertyMetaTag('og:image:height', imageHeight);
}
if (imageAlt != null) {
webify.platform.setPropertyMetaTag('og:image:alt', imageAlt);
}
if (locale != null) {
webify.platform.setPropertyMetaTag('og:locale', locale);
}
// Twitter / X
webify.platform.setMetaTag('twitter:card', twitterCardType.value);
webify.platform.setMetaTag('twitter:title', title);
webify.platform.setMetaTag('twitter:description', description);
webify.platform.setMetaTag('twitter:image', imageUrl);
if (twitterSite != null) {
webify.platform.setMetaTag('twitter:site', twitterSite);
} else if (webify.config.twitterSite != null) {
webify.platform.setMetaTag('twitter:site', webify.config.twitterSite!);
}
if (twitterCreator != null) {
webify.platform.setMetaTag('twitter:creator', twitterCreator);
}
if (imageAlt != null) {
webify.platform.setMetaTag('twitter:image:alt', imageAlt);
}
}