How do I customize of SilverStripe pages</a></h1> </div> <div class="grid fw-wrap pb8 mb16 bb bc-black-075"> <div class="grid--cell ws-nowrap mr16 mb8" title="2016-01-12 19:07:53Z"> <span class="fc-light mr2">Asked</span> <time itemprop="dateCreated" datetime="2015-08-31T07:11:05.987" class="fromnow">Aug 31 '15 at 07:11</time> </div> <div class="grid--cell ws-nowrap mr16 mb8"> <span class="fc-light mr2">Active</span> <time class="fromnow" title="2017-01-11T04:44:33.513" datetime="2017-01-11T04:44:33.513">Jan 11 '17 at 04:44</a> </div> <div class="grid--cell ws-nowrap mb8" title="Viewed 1,430 times"> <span class="fc-light mr2">Viewed</span> 1,430 times </div> </div> <div id="mainbar" role="main" aria-label="questions and answers"> <div id="question" class="question" data-questionid="32305730" data-ownerid="5257567" data-score="4"> <div class="post-layout"> <div class="votecell post-layout--left"> <div class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="32305730"> <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"></path></svg></button> <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="4">4</div> <button class="js-bookmark-btn s-btn s-btn__unset c-pointer py4"> <svg aria-hidden="true" class="svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M6 1a2 2 0 00-2 2v14l5-4 5 4V3a2 2 0 00-2-2H6zm3.9 3.83h2.9l-2.35 1.7.9 2.77L9 7.59l-2.35 1.7.9-2.76-2.35-1.7h2.9L9 2.06l.9 2.77z"></path></svg> <div class="js-bookmark-count mt4" data-value=""></div> </button> </div> </div> <div class="postcell post-layout--right"> <div class="s-prose js-post-body" itemprop="text"><p>How do I customize the <code><title></code> of SilverStripe pages? </p> <p>Right now it's</p> <pre><code><title><% if $MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> &raquo; $SiteConfig.Title</title> </code></pre></div> <div class="mt24 mb12"> <div class="post-taglist grid gs4 gsy fd-column"> <div class="grid ps-relative"> <a href="../../questions/tagged/silverstripe" class="post-tag js-gps-track" title="show questions tagged 'silverstripe'" rel="tag">silverstripe</a> </div> </div> </div> <div class="mb0"> <div class="mt16 grid gs8 gsy fw-wrap jc-end ai-start pt4 mb16"> <div class="grid--cell mr16 fl1 w96"></div> <div class="post-signature grid--cell"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="edited Aug 31 '15 at 13:23">edited Aug 31 '15 at 13:23</time> <a href="../../users/1715759/3dgoo" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/1715759.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="3dgoo" /> </a> <div class="s-user-card--info"> <a href="../../users/1715759/3dgoo" class="s-user-card--link">3dgoo</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">15,716</li> <li class="s-award-bling s-award-bling__gold" title="6 gold badges">6</li> <li class="s-award-bling s-award-bling__silver" title="46 silver badges">46</li> <li class="s-award-bling s-award-bling__bronze" title="58 bronze badges">58</li> </ul> </div> </div> </div> <div class="post-signature owner grid--cell"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Aug 31 '15 at 07:11">asked Aug 31 '15 at 07:11</time> <a href="../../users/5257567/ssguest" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/5257567.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="ssguest" /> </a> <div class="s-user-card--info"> <a href="../../users/5257567/ssguest" class="s-user-card--link">ssguest</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">129</li> <li class="s-award-bling s-award-bling__bronze" title="3 bronze badges">3</li> </ul> </div> </div> </div> </div> </div> </div> <div class="post-layout--right js-post-comments-component"> <div id="comments-32305730" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="32305730" data-min-length="15"> <ul class="comments-list js-comments-list" data-remaining-comments-count="0" data-canpost="false" data-cansee="true" data-comments-unavailable="false" data-addlink-disabled="true"> <li id="comment-52493826" class="comment js-comment " data-comment-id="52493826" data-comment-owner-id="1069828" data-comment-score="0"> <div class="js-comment-actions comment-actions"> <div class="comment-score js-comment-edit-hide"> </div> </div> <div class="comment-text js-comment-text-and-form"> <a name="comment52493826_32305730"></a> <div class="comment-body js-comment-edit-hide"> <span class="comment-copy">Are changes to the above not taking effect? Does your template include $MetaTags(true) or $MetaTags(false)? It should be the latter if you're including your own title tag. Beyond that we'll need more detail about what you're wanting to accomplish.</span> – <a href="../../users/1069828/mark-guinn" title="619 reputation" class="comment-user ">Mark Guinn</a> <span class="comment-date" dir="ltr"><a class="comment-link" href="../../questions/32305730/how-do-i-customize-title-of-silverstripe-pages#comment52493826_32305730"><span title="2015-08-31T10:45:50.880 License: CC BY-SA 3.0" class="relativetime-clean">Aug 31 '15 at 10:45</span></a></span> </div> </div> </li> <li id="comment-52495204" class="comment js-comment " data-comment-id="52495204" data-comment-owner-id="5257567" data-comment-score="0"> <div class="js-comment-actions comment-actions"> <div class="comment-score js-comment-edit-hide"> </div> </div> <div class="comment-text js-comment-text-and-form"> <a name="comment52495204_32305730"></a> <div class="comment-body js-comment-edit-hide"> <span class="comment-copy">I think I should set $MetaTags(false), it's true right now But I don't know the next step to have the title beside what I have right now which is "Menu Name>>Site Name" (the output of the code I originally submitted). I want to customize the <title> for each page. – ssguest Aug 31 '15 at 11:26

  • Once you change that true to false, I you follow 3dgoo's answer below. You can of course remove the " » $SiteConfig.Title" if you want to be able to just use MetaTitle. – Mark Guinn Aug 31 '15 at 16:25
  • 2 Answers2

    6

    Your current page template page <title> tag is:

    <title>
        <% if $MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> 
        &raquo; $SiteConfig.Title
    </title>
    

    You can change this to use any variable or content that you would like.

    Your current template code checks if the page has a $MetaTitle defined. If it does it will use this. Otherwise it will use the page $Title.

    The last part adds the site title $SiteConfig.Title to the end. This field can be found in the CMS on the Settings tab.

    The MetaTitle variable was removed from the core SilverStripe code in 3.1. If you would like to add this functionality back in you can do this by installing the SilverStripe MetaTitle module or by adding the variable and input to your Page class yourself.

    Here is some code to add the MetaTitle variable to the Page class:

    class Page extends SiteTree {
    
        private static $db = array(
            'MetaTitle' => 'Varchar(255)'
        );
    
        public function getCMSFields() {
            $fields = parent::getCMSFields();
    
            $fields->addFieldToTab(
                'Root.Main',
                TextField::create('MetaTitle')
                    ->setRightTitle('Shown at the top of the browser window and used as the "linked text" by search engines.')
                    ->addExtraClass('help'),
                'MetaDescription'
            );
    
            return $fields;
        }
    }
    

    The variable will appear in the CMS on each page underneath the Content field.

    3dgoo
    • 15,716
    • 6
    • 46
    • 58
    0

    You can set the page title in the CMS in the "Title" field.

    If you wish to change the title of the entire site, edit the Title in the Site Configuration section (which matches up to $SiteConfig.Title).

    In general, those variables are just populated from the CMS, so feel free to customize them with other variables, or edit their values in the CMS as you need.

    ss23
    • 148
    • 10
    • What I wanted to customize for each page is the which appears when you point at the tab of the browser. – ssguest Aug 31 '15 at 07:39