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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Generator HTML Tag

Go to End

16 Posts   13107 Views


Community Member, 541 Posts

29 June 2010 at 4:05am

Hi All,

Just noticed that Silverstripe 2.4 now gernerates a generator HTML tag in the sites HEAD. Though this doesn't bother me for most sites, we have some high security sites built in Silverstripe that I would feel more comfortable about removing this for.

Is this possible, and if so, how?




Forum Moderator, 5523 Posts

29 June 2010 at 10:05am

Copy the MetaTags() function from SiteTree.php to your own Page.php. Then you can customize it as much as you need.


Community Member, 541 Posts

29 June 2010 at 7:05pm

Oooo, I have always wondered how you customise MetaTags, never really put a lot of time into working it out though.

Cheers Willr!



Community Member, 18 Posts

30 June 2010 at 7:09am

Hi there, so my site works fine in every browser except for explorer (using IE7). My site header looks like this:

<% base_tag %>
<title><% if MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> &raquo; $SiteConfig.Title</title>
<link rel="shortcut icon" href="/favicon.ico" />

I like how the generator works and i would like to include it in the header. Unfortunately explorer is displaying the Custom Meta Tags in the public header of my site.

The only way i have been able to fix this is by deleting $MetaTags line from the header code but as i said, i would like to include the meta tags and the problem is with IE only.

Can someone point to how I can fix this?

Thank you, P.


Community Member, 39 Posts

30 June 2010 at 10:22am

Edited: 30/06/2010 10:25am

I like this post, because I had thought about this before, but did not know where to go to customize it a little...

I had a client ask about generating Canonical URLs for their Silverstripe I though to myself - with SS you don't really need Canonical URLs because the SS URLSegment is so sweet and simple. (Other CMS struggle at this with params etc)....

Anyways I had created a method in the Page class that generates the Canonical URL, and then when I saw this post, I thought why not customize the MetaTags function and have it generate it instead of putting the call in the .ss template.

So here goes some code.

1. Create a GetCanonical Method in your Page class controller (there are bunch of if/else statement to try and handle actions/IDs/OtherIDs in the NestedURL structure of 2.4)

function GetCanonical() {
		if (Director::urlParam('Action')) {
			$action = Director::urlParam('Action');
    		        $parameterID = urlencode(Director::urlParam('ID'));
    		        $parameterOtherID = urlencode(Director::urlParam('OtherID'));
		        if (strcmp($action, $this->URLSegment) == 0 && empty($parameterID)  ) {
				return false;
    		        } else if (strcmp($parameterID, $this->URLSegment) == 0) {
    			        return false;
    		        } else if (strcmp($action, $this->URLSegment) != 0 && empty($parameterOtherID)){
    			        return $action . '/' . $parameterID;
    		        } else {
    			        return $parameterID . '/' . $parameterOtherID;

2. Add this simple line to your MetaTags function

$tags .= "<link rel=\"canonical\" href=\"" . $this->AbsoluteLink() . $this->GetCanonical() . "\" />\n";

This should work with simple URLs as well as accomodate the case of DataObjects being displayed with action/ID functionality. Please feel free to take it, use it, or even provide feedback on a better and more efficient means to achieve this.

- Ed


Community Member, 81 Posts

3 October 2010 at 7:14am

What about custom controller?

Director::addRules(50, array('shop/$Action/$ID' => 'Products_Controller'));
class Products_Controller extends Page_Controller

I tried:

   	public function MetaTags($includeTitle = TRUE){
   			$tags = "<title>TEST</title>\n";
   			$this->extend('MetaTags', $tags);

and got nothing


Community Member, 102 Posts

23 September 2011 at 4:32am

Edited: 23/09/2011 5:10am

2 things to add to the Canonical discussion...

1) If you're just adding a tag, it's simpler to pull it into the .ss file than override the MetaTags function. (The original reason overriding MetaTags was recommended in this thread was to remove a tag.)

2) The canonical tag should include the domain name if there's a chance that multiple domains or subdomains point to the same page, so the code below uses protocolAndHost.

In the Page.php define...

	function CanonicalURL() {
		return Director::protocolAndHost() . $this->Link();

...then in

	<% base_tag %>
	<link rel="canonical" href="$CanonicalURL" />

Note that this doesn't include edk's solution for dealing with virtual pages (good point!), but the two could easily be merged...


Community Member, 8 Posts

29 September 2011 at 2:09am

Hi, I tried to use the function GetCanonical by -Ed,

so i added

- function GetCanonical() to the page.php
- $tags .= "<link rel=\"canonical\" href=\"" . $this->AbsoluteLink() . $this->GetCanonical() . "\" />\n"; to SiteTree.php

and i also added the code from inCharge

function CanonicalURL() {
return Director::protocolAndHost() . $this->Link();
to page.php

<link rel="canonical" href="$CanonicalURL" />
to the

But i only geht an empty <link rel="canonical" href="" />

Can you help?

Best regards bastiR

Go to Top