Thursday, January 20, 2011

Custom site logo not appearing on WebPart page

As you probably all know, SharePoint 2010 allows site administrators to change the sites logos just like 2007 did. This is done on the “Title, description, and icon” page

clip_image002

clip_image004

The picture then appears in the top left of the site pages, just before the page title/breadcrumb

 





clip_image006

The trouble is that this doesn’t work on WebPart pages, no matter what you do; users will still see the default yellow icon.

 

Cause

clip_image008

WebPart pages use the TitleBarWebPart, this WebPart allows you to specify a title and logo for the page using the button in the ribbon bar

The problem here is that whatever you do, this Web Part always overrides your site logo setting. If you specify a page specific logo along with the title, it will use it. If you don’t specify a page specific logo, it will use the default SharePoint logo.

This overriding is done in javascript by the code below that you will find at the end of your web part page :

var logoImg = documentGetElementsByName('onetidHeadbnnr0');
if (logoImg != undefined && logoImg[0] != undefined)
logoImg[0].src='/_layouts/images/siteIcon.png';


This javascript code is generated by the TitleBarWebPart, the “/_layouts/images/siteIcon.png” is replaced with the page specific logo if you set one. Thus this WebPart systematically overrides the site wide logo settings.
By the way you will notice that it doesn’t work under Chrome 8 because of a Javascript error.

Solution


Aaron Han suggested removing the Web part from the pages impacted on a MSDN forum:
http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010customization/thread/9706669e-0488-45cd-9cf6-2edfef91f77f
If you don’t want to edit every single WebPart page and/or if you want to retain the ability to change the page title I have another solution for you.
My solution is to change the SiteLogoImage node name in the master page. Thus the javascript generated by the PageTitleWebPart is no longer able to change the logo.

Details

Open your master page and find the line starting with:
<SharePoint:SiteLogoImage name="onetidHeadbnnr0"
And replace the “onetidHeadbnnr0” name with something else; “onetidHeadbnnr1” will do the trick.

Conclusion

I haven’t seen any drawback with this technique, yet :). Tell me if you do !

10 comments:

Christopher R said...

Thank you A LOT!! This helped me very much :) Haven't experienced any downsides on the last solution, so it's good.

Regards,
Christopher R

David M. Sterling said...

Excellent job; client discovered this and I was at a loss - thanks! Will repost on my blog as well.

Anonymous said...

Thanks a lot.

I have to change the name in the defaul.master and v4.master, and works.

Regards.

westerdaled said...

Hi

Just applied this to our custom v4.master. Why on earth is the javascript looking for the element: "onetidHeadbnnr0" which doesn't exist in the web part pages... is this a bug or intended.

Anonymous said...

Hello and thank you for your post. The side effect that I found was once you apply the fix, then users can no longer override the logo. If they set the logo in Title Bar Properties, it is simply ignored.

Graham Johnson said...

Lifesaver :) Been pulling my hair out trying to figure this. Didn't pose a problem in Chrome, the custom logo was there throughout... But IE and Forefox.. ARGH! Your solution worked a treat, no adverse side affects observed... THANKS!

Zakir C said...

Thanks for this post. The changing of SiteLogoImage attribute name really did the trick.

SANGEET AHUJA said...

Thanks
That works !!

ashish said...

There is no need to change the masterpage, instead specify the custom image path again in the webpart page's ribbon --> set tile bar properties.

Now the default site image works on all browsers.

Anonymous said...

@ashish
That's fine if you only have 1 page but we have dozens of web part pages and don't want to have to change them all again.

This is stupid behavior in the first place. There is no reason for sharepoint to change a logo using javascript. Can someone explain why this code exists?