Change Page Titles in Sitefinity 4.1 Programmatically

While creating the Sitefinity base page install for an entire website (100+ pages), I didn’t think to customize the page titles (HtmlTitles, title tags that is) while creating all the pages in Sitefinity. This became a problem later because going back through every single page and adding the same tagline for the website, “Acme Corp | *pageTitle*” would have been extremely painful, slow, and some pages inevitably would have been missed. Working with the Sitefinity team, I was able to create a Widget that would simply run through each page in the sitemap, and automatically prepend the beginning of the title to the HtmlTitle. Check past the break for the code.

**UPDATE** – Using the pipe character “|” as the original code showed, would work programmatically, but once you try to edit the Title and Properties of a page, the pipe character was deemed invalid and would not allow you save the page without changing the HtmlTitle of the page. Code is now updated to reflect the changes, using a hyphen instead.

The code below illustrates an empty Widget for re-use later if needed, and uses the FluentAPI for the pageManager structure and modification.


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ChangeTitles.ascx.cs" Inherits="Custom_Widgets_ChangeTitles" %>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Pages.Model;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity;
using Telerik.Sitefinity.GenericContent.Model;

public partial class Custom_Widgets_ChangeTitles : System.Web.UI.UserControl
	public void FindPageByTitle()
        var fluent = App.WorkWith().Pages();
        var mypage = fluent.LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
        .Where(p => p.Page != null)
		.ForEach(p => p.Page.HtmlTitle = "Acme Corp - " + p.Page.HtmlTitle.ToString())

    protected void Page_Load(object sender, EventArgs e)
Posted in C-Sharp, C#, Sitefinity 4, Telerik
  • nice work! an alternative might be to include a widget on the master page template that will update the title dynamically on load, without hardcoding it into the actual page title.

    This may sound silly (how often will your company name change?) but it does allow you more control over the content, should you someday end up with 1000 pages and need to add something like “LLC” or a new partner name to the title.

    but for one-off things like this, the fluent api sure is clea and quick!