Jump to:

23377 Posts in 18296 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » [SOLVED] How to input title tag metadata

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

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

Page: 1
Go to End
Author Topic: 269 Views
  • BigMoose
    Avatar
    Community Member
    19 Posts

    [SOLVED] How to input title tag metadata Link to this post

    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?

  • thomas.paulson
    Avatar
    Community Member
    67 Posts

    Re: [SOLVED] How to input title tag metadata Link to this post

    <?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?

  • BigMoose
    Avatar
    Community Member
    19 Posts

    Re: [SOLVED] How to input title tag metadata Link to this post

    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;
    }

    }

    269 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.