Question

I would like to have logic in the Meta Description (located in Banner Header) tag that has the following effect:

if rendering an Entry:

     <meta name="description" content="<$mt:EntryBody words="25"$>..." />
else:

     <meta name="description" content="<$mt:BlogDescription$>" />

Thanks for your help!

Was it helpful?

Solution

IfArchiveType is fine if you know you're only going to be doing one test.
With a meta description, on the other hand, there's a good chance you'll want to do something different on category pages, say. While you could just pile up individual IfArchiveType tests for each, you'd do better to familiarize yourself with the archive template variables(which provide a lot more besides) and use the generalized If/Else|If tags:

<mt:if name="entry_archive">
    <meta name="description" content="[Entry archive-specific description]" />
<mt:elseif name="category_archive">
    <meta name="description" content="[Category archive-specific description]" />
<mt:else>
    <meta name="description" content="[Site-wide fallback description]" />
</mt:if>

...which can then be further cleaned up using the Var tag:

<mt:if name="entry_archive">
    <$mt:var name="metaDesc" value="[Entry archive-specific description]"$>
<mt:elseif name="category_archive">
    <$mt:var name="metaDesc" value="[Category archive-specific description]"$>
<mt:else>
    <$mt:var name="metaDesc" value="[Site-wide fallback description]"$>
</mt:if>

<meta name="description" content="<$mt:var name="metaDesc"$>" />

[For clarity, I've omitted the modifiers Mike added, but they are a good idea to include.]

OTHER TIPS

You want the mt:IfArchiveType block tag.

<mt:IfArchiveType archive_type="individual">
  <meta name="description" content="<$mt:EntryBody remove_html="1" words="25" encode_html="1"$>..." />
<mt:Else>
  <meta name="description" content="<$mt:BlogDescription remove_html="1" encode_html="1"$>" />
</mt:IfArchiveType>

I've taken the liberty of adding some handy modifiers that will help avoid invalid output.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top