19
votes

I want the site logo link in the master page to always redirect to the root site collection home page. Default behavior is to redirect to the homepage of the current web (spweb).

Back in SharePoint 2010 I could accomplish this by adding the NavigateUrl attribute to the SPLinkButton control in the master page with a value of ~sitecollection like this:

<SharePoint:SPLinkButton runat="server" NavigateUrl="~sitecollection/" id="onetidProjectPropertyTitleGraphic">
<SharePoint:SiteLogoImage name="onetidHeadbnnr0" id="onetidHeadbnnr2" LogoImageUrl="/_layouts/images/siteIcon.png" runat="server"/>
</SharePoint:SPLinkButton>

However in SharePoint 2013 the control for the site logo link has changed in the master page to SPSimpleSiteLink. I have tried setting the NavigateUrl property for this control in the same way but it does not seem to work anymore.

<div id="siteIcon" class="ms-tableCell ms-verticalAlignTop">
  <SharePoint:AjaxDelta id="DeltaSiteLogo" BlockElement="true" runat="server">
    <SharePoint:SPSimpleSiteLink NavigateUrl="~sitecollection/" CssClass="ms-siteicon-a" runat="server" id="onetidProjectPropertyTitleGraphic" >
      <SharePoint:SiteLogoImage CssClass="ms-siteicon-img" name="onetidHeadbnnr0" id="onetidHeadbnnr2" LogoImageUrl="/_layouts/15/images/siteIcon.png?rev=23" runat="server"/>
    </SharePoint:SPSimpleSiteLink>
  </SharePoint:AjaxDelta>
</div>

As a workaround, I have now removed the AjaxDelta wrapper control and changed the SPSimpleSiteLink to the old SPLinkButton with the added NavigateUrl attribute. This seem to work.

Are there any better ways?

8

8 Answers

20
votes

Regarding MSDN SharePoint:SPSimpleSiteLink is a "very simple control which provides a link to the current site This control is compliant as a chrome control in an MDS-enabled master page"

if you want the site logo link always redirect to the site collection root site, use SharePoint:SiteLogoImage (as we was used with SP 2010)

<SharePoint:AjaxDelta id="DeltaSiteLogo" BlockElement="true" runat="server">
<SharePoint:SPLinkButton runat="server" NavigateUrl="~sitecollection/" id="onetidProjectPropertyTitleGraphic">
                    <SharePoint:SiteLogoImage  name="onetidHeadbnnr0" id="onetidHeadbnnr2" LogoImageUrl="images/logo.png" runat="server">
                                </SharePoint:SiteLogoImage>
              </SharePoint:SPLinkButton>

6
votes

As Muawiyah Shannak mentioned you simply have to replace the SharePoint:SPSimpleSiteLink with the SharePoint:SPLinkButton control.

If you are useing the SharePoint Design-Manager Snippet Tool you have to edit the following two lines (start and end tag)

<!--MS:<SharePoint:SPSimpleSiteLink runat="server" CssClass="ms-siteicon-a" ID="x7917ecc8c38d4bd69f58e338eab54c8c">-->
[...]
<!--ME:</SharePoint:SPSimpleSiteLink>-->

to this

<!--MS:<SharePoint:SPLinkButton runat="server" NavigateUrl="~sitecollection/" CssClass="ms-siteicon-a" ID="x7917ecc8c38d4bd69f58e338eab54c8c">-->
[...]
<!--ME:</SharePoint:SPLinkButton>-->

It is alays better to use a dynamic control then setting it as a permanent link, so you can reuse your template on other sitecollections without changing the static root link.

1
votes

If you need permanent link, why you use some SharePoint/ASP.NET controls - just set this link in master page :))) Think it's simpliest way, that will work in any version of SharePoint.

1
votes

The same appens to me, NavigateUrl do not work. So even if you try to change href property with JQuery some later script overwrite the href with current site url. The only way is to change the id of 'a' element to prevent overwriting. ID changing cause Sharepoint javascript error so you have to create a dummy hidden element with the same old id of the logo a element. All this work using 'seattle' master page.

So in $(document).ready do something like:

//read old link id
var oldLogoId = $("#DeltaSiteLogo > a").attr('id');
//change the id
$("#" + oldLogoId).attr('id','CustomSiteLogo');
//create dummy hidden element
$("#DeltaSiteLogo > a").after("<a id='tmpDeltaSiteLogo' href='#' style='display:none'>Dummy</a>");
//set the dummy id with old id value
$("#tmpDeltaSiteLogo").attr("id",oldLogoId );
//alter the link to point to the webroot 
$("#CustomSiteLogo").attr('href', window.location.protocol + "//" + window.location.host);
1
votes

use ../ in the NavigateUrl. This will get to the parent site.

1
votes

If you need a dynamic link you can use a UserControl in your masterpage. If you for example want to always point to the root address, but that root address is different across several environments, you could do like this in the user control:

<asp:HyperLink CssClass="ms-siteicon-a" runat="server" ID="TG_CustomSiteLink" ToolTip="Home">
        <SharePoint:SiteLogoImage CssClass="ms-siteicon-img" name="onetidHeadbnnr0" id="onetidHeadbnnr2" LogoImageUrl="/_layouts/15/images/siteIcon.png?rev=23" runat="server" AlternateText="Home"/>
</asp:HyperLink>

And in your code-behind:

public partial class CustomSiteLogoLink : UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var uri = HttpContext.Current.Request.Url;
        var url = uri.ToString();
        var rootUrl = url.Replace(HttpUtility.UrlDecode(uri.PathAndQuery), String.Empty);
        this.TG_CustomSiteLink.NavigateUrl = rootUrl;
    }
}
1
votes

For site collection redirect option, Add the attribute NavigateUrl to this tag and set it value to "~sitecollection" For site current site redirect option, Add the attribute NavigateUrl to this tag and set it value to "~site"

NavigateUrl="~sitecollection/"
NavigateUrl="~site/"

Click Here See More Details

0
votes

this is the most simple sln i could find for a simple logo that links to home page

<SharePoint:SPLinkButton id="index" ClientIDMode="Static"  CssClass="page-logo" runat="server" NavigateUrl="~sitecollection/">
<img src="<asp:Literal runat='server' Text='<%$SPUrl:~sitecollection/Style Library/images/logo.png%>' />" alt="Logo" />
</SharePoint:SPLinkButton>

P.S. yes, trying to do <%$SPUrl:~sitecollection... outside the <asp:Literal threw an exception.