ExpressionEngine - how to add meta data to entries

This applies to ExpressionEngine 4 and 5. Earlier versions don’t allow you to share fields across multiple channels.

This quick tutorial will allow you to:

  1. Add a custom page title value with a fallback
  2. Add a meta description
  3. Add other meta data as required
  4. Keep your templates DRY

Create custom fields for your meta data

For simplicity we’ll just add the two basic ones.

  • Type: Text input
  • Field name: SEO page title
  • Short name: seo_page_title
  • Maximum characters: 65
  • Text formatting: none
  • Type: Text input
  • Field name: SEO meta description
  • Short name: seo_meta_description
  • Maximum characters: 165
  • Text formatting: none

You can of course name your fields however you want.

Create a Field group

  • Name: SEO (or whatever suits you)
  • Check the meta fields you want to include in the group

Now when you assign the field group to a channel all checked fields will be included on your publish page. If you add new fields to this field group they’ll automatically be added to all your selected channels.

Assign the field group to one or more channels

Locate and edit a Channel you want to assign the field group to. Click the “Fields” tab and check the group name. Repeat for each Channel as needed.

Create a "partial" template

Partial template name: part_meta

Now add the tags you want to include, for example:

{!-- use the 'seo_page title' value if it exists, else provide a fallback --}
<title>{if seo_page_title}{seo_page_title}{if:else}{title} | {site_name}{/if}</title>

{!-- use the meta description if it exists --}
{if seo_meta_description}<meta name="description" content="{seo_meta_description}">{/if}

{!-- optionally add the author name meta value --}
<meta name="author" content="{author}">

Add the partial tag to your single entry template(s)

Add the template partial tag in a layout:meta tag, we’ll add this later to your layout template.

{exp:channel:entries channel="mychannel"}

{layout:set name="metatags"}




Add the layout set tag to your layout template


  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">



Now go and test it. When you view source you should see your meta data in place.


There’s nothing stopping you adding extra meta information to the partial template, either hard coded, or populated from another custom field. Common uses such as Open Graph and Twitter data.

You might also like

You don't know unless you ask

Contact me today