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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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

[SOLVED] How to input title tag metadata


Go to End


3 Posts   3481 Views

Avatar
BigMoose

Community Member, 19 Posts

23 February 2014 at 4:21pm

Edited: 23/02/2014 4:33pm

I'm new to Silverstripe 3.x, but had made a website previously on 2.x. Before, in the cms, under the metadata tab there existed a field which I could fill in with the page title, which would then get used for the <title> tags within the page's <head>, so that it would appear at the top of the users browser. I believe this was setting a value for $MetaTitle.

With 3.x, under the metadata tab, I only get options for Meta Description, and Custom Meta Tags. Is there a way to add the field again for $MetaTitle?

Avatar
thomas.paulson

Community Member, 107 Posts

23 February 2014 at 5:21pm

<?php

class Page extends SiteTree {

private static $db = array(
'MetaTitle' => 'Text'
);

private static $has_one = array(
);

public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', new TextField('MetaTitle'), 'Content');
return $fields;
}

}

Do dev/buill after you edit the mysite/code/Page.php?

Avatar
BigMoose

Community Member, 19 Posts

24 February 2014 at 4:41pm

Okay, I figured I would need to edit the page.php file like this. Wasn't sure if there was some way to add the field back in through the config.php file.

None the less, I did the following:

<?php
class Page extends SiteTree {

	// Adding the $MetaTitle variable back into SS3.
	private static $db = array(
    'MetaTitle' => 'Text'
	);

	private static $has_one = array(
	);
	
	public function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Main.Metadata', new TextField('MetaTitle', $title = 'Meta Title'), $above = 'MetaDescription');
    return $fields; 
    }

}