SEO A Simple Approach for meta tags with ExpressionEngine

Custom meta tags for templates/entries can be easily achieved using Template Layouts with ExpressionEngine. This approach is very lightweight, easy to customize and does not rely on an add on.

If the site already uses Template Layouts, then incorporating custom meta tags is a breeze. We’re going to start by setting a custom title and description. Here’a what a simple template layout would look like:

<!doctype html>
<meta http-equiv="content-type" content="text/html; charset=utf-8" dir="ltr">
<meta http-equiv="content-language" content="en-us" />  
<title>{if layout:title != ''}{layout:title} - {/if}{site_name}</title>
{if layout:description}<meta name="description" content="{layout:description}">{/if}

Now on any template you can easily set the title and meta description based on what the content for the template is.

{exp:channel:entries channel="news"}
{layout:set name="title"}{title}{/layout:set}
{layout:set name="description"}{meta_description}{/layout:set}

The code above will set the title to the entry’s title and the meta description to a custom field designated for meta descriptions. Additionally if you limit the custom field to 155 characters, you will ensure that the editor does not go above the limit.

The possibilities with such a simple approach are endless. Example code for category pages:

{exp:channel:category_heading channel="news"}
{layout:set name="title" value="{category_name} News"}

And my approach to paginated pages is to have the <title> tag have more than one layout variable:

<title>{if layout:title}{layout:title}{/if}{if layout:title-two} {layout:title-two}{/if} - {site_name}</title>

Having two variables allows you to set the title in pieces in different parts of the template. So pagination would look something like:

{layout="site/.html-layout" title="News"}
{exp:channel:entries channel="news" paginate="bottom" limit="10"}
{if current_page != '1'}
{layout:set name="title-two"}- Page {current_page}{/layout:set}

One last tip: assume that you don’t want the site’s name at the end of the title because the entry’s title + the site’s name may be too long. You can easily add one more template variable to the title that if set – it does not display the site’s name.

<title>{if layout:title}{layout:title}{/if}{if layout:title-two} {layout:title-two}{/if}{! if layout:no-site} - {site_name}</title>

With the above code in place, whenever you don’t want the site name in the title, just set layout:no-site to anything:

{layout:set name="no-site" value="y"}