NAME
MooX::Role::SEOTags - A role for generating SEO meta tags (OpenGraph, Twitter, etc)
SYNOPSIS
package MyWebPage;
use Moo;
with 'MooX::Role::SEOTags';
has og_title => (is => 'ro', required => 1);
has og_type => (is => 'ro', required => 1);
has og_description => (is => 'ro', required => 1);
has og_url => (is => 'ro', required => 1);
has og_image => (is => 'ro'); # optional
# And later, in the code that builds the website
my $page = MyWebPage->new(
og_title => "My Page Title",
og_type => "website",
og_description => 'This is a lovely website',
og_url => "https://example.com/my-page",
og_image => "https://example.com/image.jpg",
);
# Print tags separately
print $page->title_tag;
print $page->canonical_tag;
print $page->og_tags;
# Or print all tags at once
print $page->tags;
DESCRIPTION
This role provides methods to generate SEO meta tags for web pages, including OpenGraph and Twitter tags. It requires the consuming class to implement the following attributes or methods:
og_title - The title of the page
og_type - The type of the page (e.g., "website", "article")
og_description - The description of the page
og_url - The canonical URL of the page
og_image - The URL of an image representing the content (optional)
The role provides methods to generate individual tags as well as a method to generate all tags at once.
METHODS
title_tag
Returns the HTML title tag.
author_tag
Returns the optional HTML meta author tag.
canonical_tag
Returns the HTML canonical link tag.
description_tag
Returns the HTML meta description tag.
core_tags
Returns all core tags (title, author, canonical, and description) as a single string.
og_title_tag
Returns the OpenGraph title meta tag.
og_type_tag
Returns the OpenGraph type meta tag.
og_description_tag
Returns the OpenGraph description meta tag.
og_url_tag
Returns the OpenGraph URL meta tag.
og_site_name_tag
Returns the optional OpenGraph site name meta tag
og_image_tag
Returns the OpenGraph image meta tag if the og_image attribute is provided.
og_image_alt_tag
Returns the OpenGraph image alt meta tag is the og_image_alt attribute is provided.
og_tags
Returns all OpenGraph meta tags as a single string.
twitter_card_tag
Returns the Twitter card meta tag.
twitter_title_tag
Returns the Twitter title meta tag.
twitter_description_tag
Returns the Twitter description meta tag.
twitter_image_tag
Returns the Twitter image meta tag if the og_image attribute is provided.
twitter_tags
Returns all Twitter meta tags as a single string.
tags
Returns all tags (title, canonical, and OpenGraph) as a single string.
TAG GROUPS
This role generates the following groups of HTML tags.
Core Tags
Returned by core_tags.
<title>-
Generated by
title_tag. -
Generated by
author_tag. Optional. <meta name="description">-
Generated by
description_tag. <link rel="canonical">-
Generated by
canonical_tag.
OpenGraph Tags
Returned by og_tags.
<meta property="og:title">-
Generated by
og_title_tag. <meta property="og:type">-
Generated by
og_type_tag. <meta property="og:description">-
Generated by
og_description_tag. <meta property="og:url">-
Generated by
og_url_tag. <meta property="og:image">-
Generated by
og_image_tag. Optional. <meta property="og:image:alt">-
Generated by
og_image_alt_tag. Optional. <meta property="og:site_name">-
Generated by
og_site_name_tag. Optional.
Twitter Tags
Returned by twitter_tags.
<meta name="twitter:card">-
Generated by
twitter_card_tag. <meta name="twitter:title">-
Generated by
twitter_title_tag. <meta name="twitter:description">-
Generated by
twitter_description_tag. <meta name="twitter:image">-
Generated by
twitter_image_tag. Optional.
All Tags
Returned by tags.
This method returns all Core, OpenGraph and Twitter tags.
AUTHOR
Dave Cross <dave@perlhacks.com>
COPYRIGHT
Copyright (c) 2025-26 Magnum Solutions Ltd. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.