Lisa Wess
VP of Operations

SEO: Meta Tags

SEO: Meta Tags

Another part of SEO that many people place importance on is the ability to have appropriately populated meta tags.  Using ExpressionEngine, it is extremely easy to have page-relevant meta tags by making use of the ability to set up your own custom fields, categories, and even tags.

It is worth mentioning that there is a third-party extension and plugin combination that you can use to handle this, entitled LG Better Meta.

This can also be handled without any add-ons should you so choose.  Due to the advantages for content placement, editing, and searching most ExpressionEngine users place their content into an entry in a channel.  This may be static information, it may be your typical channel post, or it could be a product description, media review, member in a member directory, or any type of data. Since these are entries in a channel, you are already using custom fields to describe the data, so why not add a few custom fields for use with meta tags?

Let us, for example, say we want to have a meta description that is related to our entry.  So we set up a custom field:

ds_meta_description

In this case, ds is short for default_site; prefixing your custom field short-names ensures that you will avoid conflicts down the line.

There is an important characteristic for this custom field.  You want it to be formatted to type: none, as you don’t want any automatic paragraph tags or similar typography sneaking into your meta tags.

We really only want our page-specific meta tags to show up on the appropriate page, in this case, our single-entry page.  How do we actually pull this in?  Here’s a snippet of code to place on the template that you use for single-entry pages:

<head>
{exp:channel:entries channel="default_site" limit="1" disable="categories|member_data|pagination|category_fields"}
    
<title>{title} {channel}</title>
    <
meta name="description" content="{ds_meta_description}" />
{/exp:channel:entries}
</head

As you can see here, we’re dynamically pulling in both the title, as well as our ds_meta_description custom field.  All that you need to do now for this to show up is to make sure you fill in that custom field when posting your entry.

You can, of course, also do this under the Dublin Core standard, or any other standard you want; all of this works because you’re pulling your custom field into your formatted template - formatted how you’ve decided.

Since we need to use the channel entries tag to pull this data out, we can make use of any channel entries variables - including pulling out the author if you want to fill in a meta tag for author, or the date for creation date, or any other meta information you want to include.

Remember, also, that if you use the Tag Module, you are already specifying keywords for an entry, so you can pull those keywords into a meta tag quite easily. Building on our example above:

<head>
{exp:channel:entries channel="default_site" limit="1" disable="categories|member_data|pagination|category_fields"}
    
<title>{title} {channel}</title>
    <
meta name="description" content="{ds_meta_description}" />
    <
meta name="keywords" content="{exp:tag:tags entry_id="{entry_id}" backspace="2"} {tag}, {/exp:tag:tags}" />
{/exp:channel:entries}
</head

Or, say instead of tags, you wish to pull in categories as your meta keywords:

<head>
{exp:channel:entries channel="default_site" limit="1"  disable="member_data|pagination|category_fields"}
    
<title>{title} {channel}</title>
    <
meta name="description" content="{ds_meta_description}" />
    <
meta name="keywords" content="{categories backspace="2"} {category_name}, {/categories}" />
{/exp:channel:entries}
</head

As you can see from the above, since ExpressionEngine is fully templated, you have control over all aspects of the content and its presentation.  Ultimately, this means that SEO is in your hands as the designer, making use of the flexibility and power that ExpressionEngine offers to keep your content dynamic and contextual.