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

    Comments (1)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    clever solution, nick. thanks.
    June 8

    Trackbacks

    The trackback URL for this entry is:
    http://customsharepoint.spaces.live.com/blog/cns!41D760DBB8E4E638!176.trak
    Weblogs that reference this entry
    • None