Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Changing default title and meta tags


Reply


4 Posts   7658 Views

Avatar
DanStephenson

Community Member, 116 Posts

6 February 2009 at 7:46am

Hi all,

I know that a page's title can be changed in the admin panel, but then just that page's title, as entered shows up. What I was hoping for, was to create a title in this format:

Site Name - $Title

Can the title tag output using $MetaTags be customized at all? What about meta tags? I'd love to be able to enter a pre-filled list of keywords for every page, and then allow users to add to them after, same with the description.

Avatar
Howard

Community Member, 215 Posts

7 February 2009 at 4:25pm

Title: this is easily done with Silverstripe. In your Page.ss file change $Metatags to $Metatags(false) this excludes the Title from being added automagically, then you can include $Title in the head by going like:

<title>$Title - Site Name</title>

Keywords and Description: Again this is easy to edit, for each page that is created in the CMS there is a tab above the page-name editing box called "Meta-data". In this tab you can change the URL of the page and add keywords and edit the description

Avatar
DanStephenson

Community Member, 116 Posts

11 February 2009 at 5:25am

Thanks Howard, that is excellent info about the title.

I know about the tab for meta info, but is there a way I could pre-fill it with sitewide keywords for each new page, and then the author add their own to the list?

Avatar
neilcreagh

Community Member, 98 Posts

17 July 2009 at 12:32am

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.