Creating an SEO Page Title

We needed to change all of our page titles to optimize them for the search engines (SEO) but we used the page titles in all of our site navigation and we didn’t want the SEO title used in our navigation. Here’s a fairly simple solution but you have to implement it very carefully because it’s really easy to bring your entire site down with one master page publish.

The overall solution is to add a new field to your pages and then tell your master pages to use that new field for the page title. Before you start this process you should 1. Make a list of all of the master pages that will use this new field and 2. Make a list of all of the page layouts that are used by those master pages. You will be modifying all of them!

Steps

  1. Create a new site column called SEOPageTitle
  2. Add the column to your document content type(s)
  3. Change the field where the master page is pulling the page title
     <title><asp:ContentPlaceHolder id=”PlaceHolderSEOPageTitle” runat=”server”/></title>
  4. Move the default page title placeholder to a hidden ContentPlaceHolder control
    Look for this      <asp:panel visible=”false” runat=”server”>
    Add this after it      <asp:ContentPlaceHolder id=”PlaceHolderPageTitle” runat=”server”/>
  5. Check-in the master pages and make sure nothing breaks 🙂
  6. Add a placeholder control to all of the page layouts that will be accessed by the master pages. We added this just above the PageTitle ContentPlaceHolder.
    <asp:Content ContentPlaceholderID=”PlaceHolderSEOPageTitle” runat=”server”>
     <SharePointWebControls:FieldValue id=”SEOPageTitleID” FieldName=”SEOPageTitle” runat=”server”/>
    </asp:Content>
  7. Check-in all of your page layouts

That should be it. If you did everything in the correct order, your site never went down. Just a warning… We had a lot of “strange” errors while we were making these changes. We seemed to get different results on test and production at times, so good luck… 🙂

Now you just need to update all of the pages with a new SEO title

Advertisements

Add a Document Icon to the CBQ

When you want to change the look of the results in a Content By Query web part you modify the ItemStyle.xsl file in the Style Library of your site. You can find more information here.

I created a custom style to display links to documents. If you are pulling documents directly from a document library, you can make the modifications to the XSL that are documented in this posting.

My custom style is pulling links and titles from a custom list so I needed to get the file extension to generate the icon. Luckily there’s a function in the ddwrt namespace for doing this. It’s documented here.
ddwrt:GetFileExtension(@URL)

So now you just need to build the link to the image and link it to the document URL. My variable with the document URL is @DocURL. You should substitute your own doc URL variable. Just add this to your style where you want the icon to appear.
<A TABINDEX=-1 href={@DocURL} target=_blank>
<img border=0 src=/_layouts/images/ic{ddwrt:GetFileExtension(@DocURL)}.gif alt={@DocIcon} style=vertical-align: middle;margin-right:4px />
</
A>