Anyone who's been paying attention to content strategy lately knows that the actual content of your page is what makes the biggest difference in improving your SEO, but, Google and the rest still like seeing relevant title and meta tags on your website. When we design new websites for our clients, we usually use SEO Lite, IfElse, and some clever template code.
SEO Lite
SEO Lite is a nifty little add-on that adds a tab the the content entry form with fields for a title, keywords, and description. If any fields are left blank, it will fall back on the default values you've provided. This is all well and good, but, there are a few different situations where it needs a little assistance knowing which, if any, entry's metadata to associate with a page.
Example Header Template
This is a bit of the code we include within our usual ExpressionEngine header template.
{exp:ifelse parse="inward"}
{if "{embed:meta_title}"}
{exp:seo_lite title_override="{embed:meta_title}" default_keywords="{embed:meta_keywords}" default_description="{embed:meta_description}"}
{if:elseif "{embed:entry_id}"}
{exp:seo_lite entry_id="{embed:entry_id}"}
{if:else}
{exp:seo_lite use_last_segment="yes"}
{/if}
{/exp:ifelse}
Option 1: Specify the Title in Template Embed; Optionally Display Default Keywords/Description
This logic allows you to specify a title tag manually in your template by using parameter called meta_title where you embed your header, for instance:
{embed="site/.header" meta_title="This is a Page From a Template, Not From an Entry"}
A page generated with an embed like this have a <title> tag with the value that you've specified, and fall back on your default description and keywords you've specified in SEO Lite. Obviously you don't want the same keywords and description getting repeated across several pages on your site, so this is a special case reserved for pages where the keyword and description tags aren't important - perhaps for pages you have excluded from indexing via robots.txt or <meta name="robots" content="noindex">.
If you've got a page with content that you do want indexed, you can optionally set keywords and a description:
{embed="site/.header" meta_title="This is a Page From a Template, Not From an Entry" meta_keywords="template, page, seo" meta_description="A Nifty Idea!"}
Option 2: Specify an Entry ID in Template Embed; Use Entry's Title/Keywords/Description
If you haven't specified a title tag via the meta_title parameter in our heading embed, the code will check to see if you've included an entry ID, for instance:
{embed="site/.header" entry_id="1337"}
This is especially useful for your site's primary index template (your homepage), where SEO Lite cannot rely on a URL segment to determine the entry ID. As you might expect, this embed example would display the SEO Lite information for entry 1337.
Option 3: Reply on the Last URL Segment; Use Entry's Title/Keywords/Description
Last but not least, if there isn't a meta_title or entry_id parameter in your embed tag, SEO Lite will do it's best to display the meta information based on the entry referenced in the final URL segment, which is what ends up happening in most instances.
Why Not Use SEO Lite's The Ultimate Setup™?
SEO Lite's documentation has this nifty setup:
{exp:seo_lite use_last_segment='yes' title_postfix='{embed:title_postfix}' default_title='{embed:default_title}' default_keywords='{embed:default_keywords}' default_description='{embed:default_description}'}
This is a good solution, but, it makes these assumptions:
- The homepage should display the default SEO Lite title/description/keywords, or, they should be hard coded within the index template.
- Every page will either have a reliable final URL segment or the title/description/keywords will be provided as parameters.
This assumption relies on your content editors following a different procedure for updating metadata on the homepage than they do for (most of the) other pages on the site, which could very well end up wasting time down the road with training, support, etc.
Why Use an Add-on Instead of Custom Fields?
Because it's much easier to install Simple SEO and use this template code than it is to setup and modify custom fields for storing keywords and descriptions in each channel. Why waste time keeping track of whether or not your embed should include meta_description="{pages_meta_description}" or meta_description="{news_meta_description}" if you don't have to?
What's Up with this IfElse Add-on?
This saves us a bit of overhead because it prevents ExpressionEngine from executing unneeded code within each of these conditionals. If you're not familiar with complex conditionals in ExpressionEngine, take some time to learn about IfElse and Switchee.
