Change SharePoint Master Page PlaceHolderPageTitle with jQuery

Posted on Updated on

In SharePoint, the object “PlaceHolderPageTitle” is responsible to render the Title. So if you have a property to bind the text, you should be able to render like this:

Property to include object titles

<SharePoint:ProjectProperty Property="Title" runat="server" />

In the Master Page

<SharePoint:PageTitle runat="server">
      <asp:ContentPlaceHolder id="PlaceHolderPageTitle" runat="server"><SharePoint:ProjectProperty Property="Title" runat="server" /></asp:ContentPlaceHolder>
 </SharePoint:PageTitle>  
 
The Span that Renders the Place Holder is:
 
<span id="DeltaPlaceHolderPageTitleInTitleArea">
     <asp:ContentPlaceHolder ID="PlaceHolderPageTitleInTitleArea" runat="server" />
</span>  
 

Using jQuery, you can change what ever you want, in this case the object Title.

I suggest to use ExecuteOrDelayUntilScriptLoaded because in this case you are sure that the DOM is loaded, preventing conflicts between jQuery functions

Change Title

<script type="text/javascript">
  ExecuteOrDelayUntilScriptLoaded(function () {    
    $('span#DeltaPlaceHolderPageTitleInTitleArea').each(function () {      
         $(this).empty();
         $(this).append(“OK i want this one”);
    });
}, "sp.js"); 
</script> 
 
Change if specific number of characters reached
 
<script type="text/javascript">
  ExecuteOrDelayUntilScriptLoaded(function () {    
    $('span#DeltaPlaceHolderPageTitleInTitleArea').each(function () {
        if ($(this).text().length >= 103) {
            var tituloPageTitle = $(this).text().substr(0, 100) + "...";
            $(this).empty();
            $(this).append(tituloPageTitle);
        }
    });
}, "sp.js");
</script> 
 

Good Luck 😉

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s