4

I've followed these instructions to change the default header of the SharePoint(2013)'s site.

The code I used is this:

$webApp = Get-SPWebApplication https://<intranet>
$webApp.SuiteBarBrandingElementHtml = "<div class=""ms-core-brandingText""><a href=""https://<intranet>""><img alt=""https://<intranet>/SiteAssets/Logo.png"" src=""../SiteAssets/Logo.png"" /></a></div>"
$webApp.Update()

What I tried to achieve by this is a kind of hack to have a different kind of image for each of my site across the site collection. So basically the header retrieves the image from its own SiteAssets -folder where I've placed the Logo.png. As expected, I'm only using the same name, but the image varies.

Now this works totally fine and as expected, except once I access any content of the site which has the ".../_layouts/..." -path in it. So for example once I go to site's Site settings or Site contents the image gets broken. If I follow the path of the image it shows it as ".../_layouts/SiteAssets/Logo.png" which is actually a totally blank page.

I thought this could be passed by using some kind of if -statement on Management Shell, but I haven't got it working at all - don't know if it's even possible.

My current goal is to have those broken images replaced by the default image which is located at the root, https://[intranet]/SiteAssets/Logo.png. Of course the Site settings pages could have their own logos too, but for now I'd be happy with even some sort of fix for this issue.

Also should I mention that this problems exists on My sites too. I have the My sites created as a site collection under the root web application. The paths under my sites are like this:

Broken image link: https://[intranet]/sites/SiteAssets/Logo.png

The actual path for the link: https://[intranet]/sites/my/SiteAssets/Logo.png

3
  • So you have different logos for different subsites or different site collections? Dec 16, 2013 at 14:45
  • Different logo for different subsites, but the my sites are on different site collection than the other part of the sites. To make it clear: I have a web app with two site collections - one for my sites and one for the "intra"
    – moe
    Dec 16, 2013 at 14:49
  • Apparently the example links didn't show up correctly as <, > -marks around the path, so i changed them to [, ]
    – moe
    Dec 16, 2013 at 14:51

2 Answers 2

3

You should use /sites/my/SiteAssets/Logo.png as URL

Hope it will work for you.

Use jQuery in your master page then use below code in your master page

$( document ).ready(function() {
 var pathname = window.location.pathname;

 if (pathname.indexOf("sites") >= 0)
   $('.ms-core-brandingText img').attrib('src','/sites/my/SiteAssets/Logo1.png');
 else
   $('.ms-core-brandingText img').attrib('src','/sites/my/SiteAssets/Logo2.png');
});

I am just giving you logic how to do it.

3
  • Check my answer which is edited
    – Milind
    Dec 16, 2013 at 14:53
  • Hey and thanks for your reply. If I use the path you suggested I'll have working header logo on every one of my page, but it's the same on everyone of them as the path doesn't include the ".." on start of it. The goal of mine is to achieve a header logo which varies depending on which subsite the user is on. So for example if the user is on Discussion Board type of subsite, the logo would be the kind of which describes the type of the subsite - and the logo would be retrieved from the current site's SiteAssets folder.
    – moe
    Dec 16, 2013 at 15:10
  • Find my answer edited.
    – Milind
    Dec 16, 2013 at 16:11
2

Thanks Milind. Took your script into modification and managed to get it to work (almost) properly.

In the end the script became the following:

<script type="text/javascript "src="https://mypath.com/SiteAssets/jquery.min.js" </script>
<script type="text/javascript">
$( document ).ready(function() {
var pathname = window.location.pathname;

if (pathname.indexOf("_layouts") >= 0)
$('.ms-core-brandingText img').attr('src','https://mypath.com/SiteAssets/Logo.png');
else
$('.ms-core-brandingText img').attr('src','../SiteAssets/Logo.png');
});
</script>

I entered the same for the masterpage of the My Sites using sites/my at the pathname.indexOf.

Now the only parts where the header logo isn't working are pages such as mypath.com/SiteAssets, but that should be only a small fix to the code.

Once more, thanks for leading me to the right path.

1
  • If one of the answers solved the problem statet in your question, you should mark this answer as accepted answer to help future visitors.
    – Benny Skogberg
    Jan 9, 2014 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.