5554 Posts in 1742 Topics by 1227 members
|Go to End|
24 February 2009 at 2:10pm
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.
25 February 2009 at 4:15am
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?
25 February 2009 at 9:12am
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??
25 February 2009 at 10:06am
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:
so you should be able to use those variables in your template just as you describe
17 July 2009 at 12:33am
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:
Then, on the main Page.ss template call your Meta Tags like so:
<title><% if MetaTitle %>$MetaTitle<% else %>$Title » <% control GetHomePage %>$MetaTitle<% end_control %><% end_if %> </title>
<meta name="title" content="<% if MetaTitle %>$MetaTitle<% else %>$Title » <% 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.
|Go to Top|