Package: wagtail-metadata
This plugin adds custom properties to your page models and then lets you output meta-attribute tags  using the included template tag.
These tags help with search engine optimisations and for creating nice shareable links for social media, mainly Facebook and Twitter.CompatibilityWagtail-metadata works with Wagtail v5.0 and upwards.
For compatibility with older versions of Wagtail, see past releases.InstallingFirst, install using pip:pip install wagtail-metadataThen addwagtailmetadatato your project’sINSTALLED_APPS:INSTALLED_APPS=['home','search',# etc...'wagtail.contrib.settings','wagtail.contrib.modeladmin',# etc...# Add the following:'wagtailmetadata',]UsingPages should inherit fromwagtailmetadata.models.MetadataPageMixin.
This provides asearch_imagefield in the Wagtail interface for that page type.
The description for the page will be pulled from thesearch_descriptionpage.
Metadata for the page will then be built from the page details.fromwagtail.core.modelsimportPagefromwagtailmetadata.modelsimportMetadataPageMixinclassContentPage(MetadataPageMixin,Page):passNoteEnsure you putMetadataPageMixinbeforePage.If you want to use this with a non-page model,
or want to use a different implementation for the fields,
you can inherit fromwagtailmetadata.models.MetadataMixin.
You will need to implement the following methods:fromwagtailmetadata.modelsimportMetadataMixinclassCustomObject(MetadataMixin,object):defget_meta_title(self):"""The title of this object"""return"My custom object"defget_meta_url(self):"""The URL of this object, including protocol and domain"""return"http://example.com/my-custom-object/"defget_meta_description(self):"""
        A short text description of this object.
        This should be plain text, not HTML.
        """return"This thing is really cool, you should totally check it out"defget_meta_image_url(self,request):"""
        Return a url for an image to use, see the MetadataPageMixin if using a Wagtail image
        """return'https://neonjungle.studio/share.png'defget_meta_twitter_card_type(self):"""
        What kind of Twitter card to show this as.
        Defaults to ``summary_large_photo`` if there is a meta image,
        or ``summary`` if there is no image. Optional.
        """return"summary_large_photo"If your custom object uses Wagtail images, you may wish to use the intermediary mixinwagtailmetadata.models.WagtailImageMetadataMixinso you can use the relationship for the image related metadata:fromdjango.dbimportmodelsfromwagtailmetadata.modelsimportWagtailImageMetadataMixinclassCustomObject(WagtailImageMetadataMixin,object):share_image=models.ForeignKey('wagtailimages.Image',ondelete=models.SET_NULL,null=True,related_name='+')defget_meta_image(self):returnself.share_imageDisplayDjangoTo use this in a template, first load the template tag library,
and then insert the metadata by placing{% meta_tags %}into the<head>:{%loadwagtailmetadata_tags%}{%meta_tags%}By default, this will look for aselfobject in the context to pull the metadata from.
You can specify a different object to use if you need to:{%loadwagtailmetadata_tags%}{%meta_tagsmy_custom_object%}Jinja2Addwagtailmetadata.jinja2tags.WagtailMetadataExtensionto the template extensions
in yoursettings.py:TEMPLATES=[{'BACKEND':'django.template.backends.jinja2.Jinja2','OPTIONS':{'extensions':['wagtailmetadata.jinja2tags.WagtailMetadataExtension'],},}]Insert the metadata by placing{{ meta_tags() }}into the<head>:{{ meta_tags() }}By default, this will look for apageobject in the context to pull the metadata from.
You can specify a different object to use if you need to:{{ meta_tags(my_custom_object) }}Troubleshooting‘meta_tags’ missing request from contextThe template that is trying to render themeta_tagstag does not have arequestobject in the context.‘meta_tags’ tag is missing a model or objectThere was no model passed to the template tag, orselfis not found in the current context.Adding extra tagsIf you need to add extra meta tags, to add the twitter:site tag for example,
you can extend the Wagtail Metadata template.
First, create any models that you might need to hold the extra data:fromwagtail.contrib.settings.modelsimportBaseSetting,register_setting@register_settingclassTwitterName(BaseSetting):handle=models.CharField(max_length=20)You could also add extra fields to a page model and output them as meta tags:classMyPage(MetadataPageMixin,Page):body=RichTextField()author_twitter_handle=models.CharField(max_length=20)Then, override thewagtailmetadata/parts/tags.htmltemplate
and add your tags to the relevant blocks:{% extends "wagtailmetadata/parts/tags.html" %}

{% block twitter %}
    {{ block.super }}<metaname="twitter:site"content="@{{ settings.myapp.TwitterName.twitter_handle }}"/><metaname="twitter:creator"content="@{{ model.author_twitter_handle }}"/>{% endblock %}Thewagtailmetadata/parts/tags.htmltemplate defines the following blocks
you can override or extend:{% block tags %}This block surrounds the whole template.
You can override this block to append extra tags before or after the standard tags.{% block twitter %}This block surrounds the Twitter card tags.{% block opengraph %}This block surrounds the Open Graph tags{% block meta %}This block surrounds the standard meta tags defined in HTML.Customising the share image renditionBy default, the share image rendition is set tooriginaland will use the full size image.If you wish to use a different rendition, you can set theWAGTAILMETADATA_IMAGE_FILTERsetting to change the filter used. e.g.WAGTAILMETADATA_IMAGE_FILTER='fill-1200x630'