Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Global Meta-data

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1781 Views
  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Global Meta-data Link to this post

    Hi Is there a way of specifying default meta-tags in the CMS. A lot of my small client sites just don't use the meta-fields on each page, so being able to set a default (which can be overridden) would be great.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Global Meta-data Link to this post

    Hi Tsunami

    this page might be of help: http://doc.silverstripe.org/doku.php?id=recipes:adding_metatags

    Do you want your clients to be able to change them or are you just going to set them yourself, in which case you can use the above method or simply just put them in the Page.ss template?

  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: Global Meta-data Link to this post

    That's a good start thanks aram...

    Ideally what I would like to do is set global meta-data for the site in the page template, but then add any page specific keywords (from the cms) to the global tag. Is there any way to reference individual meta fields, something like this in the template.ss:

    <meta name="Keywords" content="beach accommodation luxury $MetaKeywords" />

    Is there a document that tells me all of the CMS tags I can reference in my templates??

    Cheers

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Global Meta-data Link to this post

    I think you can actually do exactly that!

    Have a look at sapphire/core/model/sitetree (which is the class that Page extends). In its $db array it has:

    MetaKeywords
    MetaDescription
    MetaTitle
    ExtraMeta

    so you should be able to use those variables in your template just as you describe

  • neilcreagh
    Avatar
    Community Member
    88 Posts

    Re: Global Meta-data Link to this post

    Hi Guys,

    I've added default global Meta Tags by using the Homepage Meta Tags as the default set, then only replacing them if individual meta tags are actually specified for that page. So, if most pages have no meta tags set tehn the homepage set will be used as default but if one of the pages has a different title, or description or keywords it will use them.

    You can have the correct page title appear in the default set on each individual page. So, if a page has left any Meta tags blank it actually uses the default set (homepage tags) PLUS the actual page title. eg. About Us ›› The ABC Company Website

    To do this you need to add a simple function to your Page_Controller in Page.php:
       function GetHomePage(){
       return DataObject::get("HomePage");
       }

    Then, on the main Page.ss template call your Meta Tags like so:

    <title><% if MetaTitle %>$MetaTitle<% else %>$Title &raquo; <% control GetHomePage %>$MetaTitle<% end_control %><% end_if %> </title>

    <meta name="title" content="<% if MetaTitle %>$MetaTitle<% else %>$Title &raquo; <% control GetHomePage %>$MetaTitle<% end_control %><% end_if %>" />

    <meta name="description" http-equiv="description" content="<% if MetaDescription %>$MetaDescription<% else %>$Title <% control GetHomePage %>$MetaDescription<% end_control %><% end_if %>" />

    <meta name="keywords" http-equiv="keywords" content="<% if MetaKeywords %>$MetaKeywords<% else %>$Title <% control GetHomePage %>$MetaKeywords<% end_control %><% end_if %>" />

    Hope this helps!

    ps. By default Silverstripe populates the MetaTitle with the page title, so I've included the Default Title from the Homepage after it.

    1781 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.