How to Put Your CMSMS Metatags on Autopilot

What i love about CMS Made Simple and Smarty Templating engine is that many issues can be solved with very little effort.
As we all know, maintaining a website can sometimes become fairly painful and time consuming. This can also involve setting and maintaining Meta tags.

Some of you probably know there are SEOTools modules or Autometa plugins that can help in these terms, but as I am not a big fan of using modules when there is no real need for it, I want to show you how easy it is to setup automated Meta tags with nothing but Smarty and our content.

First thing we need to do is open up our page template, and assign our content and title tags as we want to use it multiple times in our template.
Right after {process_pagedata}, add the following:

{strip} {* use strip to get rid of whitespace *}
{content assign="get_content"}
{if !isset($get_title)}
    {title assign='get_title'}
{/if}
{/strip}

In this step we assigned our {content} tag and captured the {title} tag. If statement is used to replace page titles with titles from News modules, you can find detailed descriptions about this in Wayne’s post, which we will come back to.

As we have assigned title and content, you should remember that we have two variables instead of regular tags. This also means that you should replace the {content} tag in your template with {$get_content} and {$get_title} for {title}.

Now, as <title> comes first, we will edit this part:

<title>
  {$get_title} - {sitename}
</title>

As we have our title set, we can move on to the rest of our Meta tag structure:

<meta name="title" content="{$get_title} - {sitename}" />
<meta name="copyright" content="{sitename}" />
<meta name="description" content="{$get_content|strip_tags|truncate:'150'|strip}" />
<meta name="keywords" content="{search action='keywords' count='15'}" />
<meta name="language" content="{$lang}" />
<meta name="url" content="{root_url}" />
<meta name="identifier-URL" content="{root_url}" />
<meta name="revised" content="{modified_date format="%a, %d %b %Y %H:%M:%S"}" />
<meta name="original-source" content="{if isset($canonical)}{$canonical}{elseif isset($content_obj)}{$content_obj->GetURL()}{/if}" />

So what did we do so far?

As you can see, each of our Meta tags is populated with Smarty tags. This means that so far, our content is populated automatically, meaning simply that it is now “Set it and forget it”.

We have used our {$get_title} variable for the “title” tag, then as we have {sitename} available we can use it for the “copyright” tag, but you could also use a GCB for this part if the sitename isn’t identical to the company name.
Our {$get_content} is used to populate the “description” tag, we could also use strip_tags modifier to remove HTML tags from the content and truncate to limit the number of characters.
The “keywords” tag is simply using the {search} Module tag, but it is advisable that you check this part from time to time and exclude unneeded keywords in the Search Module options.
For “url” and “identifier-URL” tags, we simply use {root_url}. For “revised” tag we made use of the {modified_date} Plugin that comes with CMSMS core. This way, when a page is updated, this part is updated as well.
In the “original-source” tag, we used a part of code that is already included in Default CMSMS Templates for the <link rel=”cannonical” href=”#” /> tag.

I usually place the above code simply in the template, as it is not likely that I would need to update it regularly. However, it would also work from “Global Settings -> Global Metadata” of the CMSMS system if you prefer it.

What about Modules?

As I mentioned before, we will look at News Module as a sample of how you could populate the above tags with other Modules.
What we need to do now is to open up the News Detail Template in “Content -> News -> Detail Templates” and edit it by adding the following code on top of our News Template:

{if isset($entry->canonical)} 
    {assign var='canonical' value=$entry->canonical}
{/if}
{assign var='get_title' value=$entry->title}
{if $entry->summary}
    {assign var='meta_descr' value=$entry->summary|truncate:'150'|strip_tags|strip}
{else}         
    {assign var='meta_descr' value=$entry->content|truncate:'150'|strip_tags|strip}
{/if}
{if $entry->postdate}
    {assign var='meta_date' value=$entry->postdate|date_format:'%a, %d %b %Y %H:%M:%S %z'}
{/if}

You should be familiar with the first part, as it is included in Default templates. Then, we have our $entry->title assigned as {$get_title}. Now, you know what we did in the steps described before and next we have to assign summary or content part of News to a {$meta_descr} variable and finally, we have assigned postdate to the {$meta_date} variable.

As we have our variables set, “title” tag should already work with the {ldelim}$get_title{rdelim} variable and now all we need to do is change a few lines of our Meta tag part that we did before.

First, we edit the “description” tag, as we have the {ldelim}$meta_descr{rdelim} variable available if viewing the detail page of the News post, we can now check for $meta_descr. If the variable is available, our page content is replaced with the news content.

<meta name="description" content="{if isset($meta_descr)}{$meta_descr}{esle}{$get_content|strip_tags|truncate:'150'|strip}{/if}" />

Next would be the “revisied” tag, as we have assigned our postdate to {ldelim}$meta_date{rdelim}, we can now use it for this part.

<meta name="revised" content="{if isset($meta_date)}{$meta_date}{else}{modified_date format="%a, %d %b %Y %H:%M:%S"}{/if}" />

Well that’s it! We now have fully automated Metatags for our content and news pages. Note that you are not only limited to my examples above and you can use the same methods for Open Graph Protocol tags or the new IE9 feature “Pinned Site“. For example, you could even add the latest News posts to msapplication-task tag or Shortcuts to your Contact page or whatever you prefer, where users could quickly access these links from their Windows 7 taskbar.

Hope I was able to give you some ideas and tips in this post. Have fun trying it!

Looking for CMS Made Simple Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , , , , | Posted under CMS Made Simple | RSS 2.0

Author Spotlight

Goran Ilic

Goran Ilic

Goran Ilic is a designer, all-rounder, husband, father, and founder of a CMS Made Simple related blog called: I do this (www.i-do-this.com). After long search for a perfect tool for his clients he has found CMSMS and devoted his passion to it.

7 Comments on How to Put Your CMSMS Metatags on Autopilot

  1. thank you so much. Very valuable blog.

  2. jissey says:

    Many thanks Goran, very good tips as always

  3. (M) says:

    I get this error: “An error occurred parsing content blocks (perhaps duplicated block names)”
    I use only {content} in my template.
    If I disable {content assign=”get_content”} it works fine…

  4. Goran Ilic says:

    With {content assign=”get_content”} you assign it to $get_content variable, which means you should use {$get_content} instead of {content}

  5. Hello! Would you mind if I share your blog with my twitter group?
    There’s a lot of folks that I think would really enjoy your content. Please let me know. Many thanks

  6. Great post! I can see this being really useful for sites with so many pages that writing an individually optimized title & description for each isn’t feasible or for pages with constantly updated content. Thanks for sharing!

Leave a Reply

Your email address will not be published. Required fields are marked *


9 − 1 =

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>