Nick's profileSharePoint DevelopmentBlogListsNetwork Tools Help

Blog


    April 09

    Customizing SharePoint Page Title and META Tags

    Recently, our group deployed a public SharePoint site for a client.  After deployment, the client requested the ability to control a page’s title and META tags at any given moment. For example, they wanted to change how product lines were indexed by Google, or how Google crawls the META tags of a particular page.  I was immediately frightened by the idea of giving them access to SharePoint Designer and letting them rip away at each page’s source.

    In the end, I decided to build a custom web part that the user could simply drop on the desired page.  Upon Page Load, this invisible web part queries a SharePoint List containing a mapping to other content lists within the site and obtains the user’s desired page title.  The code then finds the PlaceHolderPageTitle content place holder, clears the controls from it, and adds in an EncodedLiteral with the new Page Title text.

    The user also has the ability to create the Keywords and Description META tags for an individual page through this web part’s Personalization properties.

    This tool could prove to be quite powerful with regard to content management in the SharePoint public Internet site realm.  Try to view it from a site owner’s perspective.  Any person in charge of a product or product line now has far greater control over how a crawler will index their pages.  More importantly, it saves the people that deployed the site hours of headaches after someone accidentally rips out some relatively important source code on their home page!

    Below are some screenshots of the code and its results:

    private void OverridePageTitle(ArrayList queryStrings)
            {
                        EncodedLiteral pageTitle = new EncodedLiteral();
                        string literalText = string.Empty;  //you will want to build in a routine that populates this literalText

                        ContentPlaceHolder contentPlaceHolder = (ContentPlaceHolder)Page.Master.FindControl("PlaceHolderPageTitle");

                        contentPlaceHolder.Controls.Clear();

                        pageTitle.Text = literalText;
                        pageTitle.EncodeMethod = SPEncodeMethod.HtmlEncode;

                        contentPlaceHolder.Controls.Add(pageTitle);
              }

             

        private void CreateMETA(string metaTagName, string metaTagContent)

        {

                 HtmlMeta mKey = new HtmlMeta();

                 mKey.Name = metaTagName;

                 mKey.Content = metaTagContent;

                 Page.Header.Controls.Add(mKey);

         }

     

    ScreenHunter_03 Apr. 09 14.44

    Page Title Before:

    TitleInfo

    Page Title After:

    TitleInfo

    Page META (Keywords/Description) before:

    NONE!

    Page META after:

    ScreenHunter_08 Apr. 09 14.53

    December 11

    Inaugural Post!

    Greetings!  This post marks the start of my new blog.  The writings here will be mainly focused on tips, tricks, and tutorials for custom development in MOSS 2007 (as well as WSS 3.0).  I will also try to include any new developments within the MOSS developer community with regard to the latest and greatest tools and utilities.
     
    You may also want to check out Mauro Cardarelli's blog, or Nick Bisciotti's blog for additional SharePoint goodies.  Both are extremely informative on a wide range of SharePoint topics.
     
    Also, this site is best viewed with Internet Explorer 7.