Archived blog with a focus on DotNetNuke news, tips and tricks, DNN SEO, and insights and opinions about the DNN community at large.

First time here? You may want to check out the blog archive, subscribe to the RSS feed, sign up for free email updates, or follow me on Twitter. Thanks for visiting!

Fixing the DNN Breadcrumb Skin Object 

We've all seen them; the bar of links usually found at the top of websites with multi-level navigation. Location breadcrumbs aide visitors in traversing content-rich sites by providing feedback on how "deep" visitors have navigated into the site and on how to get back where they came from. If properly implemented as text links, breadcrumbs also provide SEO benefits by allowing search engine spiders to more effortlessly crawl web content.

The DNN breadcrumb skin object, which is installed by default, makes it easy to implement breadcrumbs in your skins so there is really no excuse not to use them. Placing this line <dnn:Breadcrumb runat="server" id="dnnBreadcrumb" RootLevel="0" /> into your ascx-based skin renders the path to the currently selected tab in the form of TabName1 > TabName2 > TabName3. Optionally, you may specify a breadcrumb separator and a CSS class.

The only rub that I have with DNN's breadcrumb skin object is that the last item in the trail also renders as a link. You may think "what's the big deal," but I like to argue that this shortcoming works against the very benefits discussed above. Why would I want to navigate to the page that I'm already on?

So what's a dedicated DNNer to do? Here are 3 approaches one might take to "fix" the DNN breadcrumb skin object:

  1. Hack the breadcrumb trail with JavaScript.
  2. Modify the DNN skin object code.
  3. Write a custom breadcrumb skin object.

Let's look at these approaches one at a time.

JavaScript Hack

We simply target the last item in the breadcrumb trail and remove the href attribute. We then adjust the style due to the fact that even without a href attribute the <a> tag remains, which means it takes on the default link style although it's not a "live" link. Download the script here. Not the most elegant solution, but it works.

Modify the DNN Skin Object Code

This time around we add an additional public property - LastAsSpan - to the Public Members region of breadcrumb.ascx.vb that allows us to enable or disable the rendering of the last item in the breadcrumb trail as a link. Still in breadcrumb.ascx.vb, we then turn our attention to the Page_Load event handler and add a few lines of code that ultimately process our new setting. Download the commented code and then backup and replace breadcrumb.ascx.vb in admin/skins. No recompiling necessary, but you may have to restart DNN to clear the cache. For the politically correct, this constitutes a DNN core change and therefore gets overwritten by subsequent DNN upgrades. So again, far from ideal and more an illustration of concepts then a real-world solution.

Write a Custom Skin Object

This approach makes the most sense on all fronts and follows the "official" guidelines on extending DotNetNuke. Just install the custom skin object, register the new control and change the breadcrumb declaration in your existing skins and you are done. More details in the free download. I'm only a DNN module developer during REM though, so for anyone interested in the nitty-gritty of writing your own skin objects, keep an eye on Mitchel Sellers' blog later this week.

So there you have it, 3 roads to breadcrumb heaven. I'll leave it up to you to decide what approach works best for your unique situation.

In closing, I would like to thank Vasilis Terzopoulos and Mitchel Sellers for their generous contributions to this post. As always, post your comments and questions below. And if you have enjoyed this material, consider subscribing to our RSS feeds or signing up to get blog updates by email.

 




Comments

Sam MacDonald Sam MacDonald says:

Great article on how to accomplish this. I like the direction you took of writing about three options to accomplish the task. Instead of just taking and specifying one way of doing it.

Tom Kraak Tom Kraak says:

Thanks for picking up the post on your blog ... much appreciated!

Vitaly Kozadayev Vitaly Kozadayev says:

Great post. Quick note, though - in the email, all links are broken because HREFs are relative paths...

Also, can you give me some guidance/pointers on ASPDOTNETSTORE module? I just got it and wanted to learn from you, as you said elsewhere that you use it often?

Tom Kraak Tom Kraak says:

Sorry about the broken links in the email, I totally forgot.

ASPDNSF was generous enough to send me an eval copy for review, but I just haven't gotten around to it yet.

Do you have specific questions? Have you installed it yet?

erik erik says:

I like having the last page a link. It gives a quick way to reload the page.

Tom Kraak Tom Kraak says:

Erik - I don't think most "casual" users browse the web on that level.

Mitchel Sellers Mitchel Sellers says:

I finally got the tutorial that Tom was talking about posted today. Sorry for the delay. You can click on my name in this signature to go directly to the article.

Corinne Corinne says:

Hi Tom,
Great post! Couldn't agree more. Realize this is a long time after the fact, but any chance of getting the source for this skin object? Would like to use it and remove the last breadcrumb entirely - my client feels it is redundant as it repeats the page title.

Thanks in advance!
Cheers,
Corinne

Rodney Joyce Rodney Joyce says:

Good job Tom! I'll extend the skinobject for now - I raised this post in Gemini, hopefully they will add that property - http://www.dotnetnuke.com/Community/Forums/tabid/795/forumid/-1/postid/296420/scope/posts/Default.aspx

GAM GAM says:

Hello,
Please let me know, if you have any idea for Hide breadcrumb programmatically.

I need to hide breadcrumb from my Home page only.

Thank You.

Rodney Joyce Rodney Joyce says:

GAM - just make a copy of your home page skin and remove the breadcrumb for all the other pages.

Ken Tarwood Ken Tarwood says:

Heya Tom!

As you know I've been looking at little things I can do to boost our pageranks. I'd like to be able to add an H1 tag representing each page's name without changing our look & feel. I wondered if it would be worth it to write a custom breadcrumb skin object that wraps the last item in the trail with an H1 and just style it to make it look like the rest of the crumbs in the trail. We generally turn off container visibility (at least currently) and it seems duplicative to use a container heading for an H1 - especially as one can have multiple containers on a page.

Do you see any issues with this approach?


Thanks!
Ken

Rodney Joyce Rodney Joyce says:

Hi Ken,

There really should be only 1 H1 tag on the page and your main page title should be that one. I was reading a good book (Steve Krug - Don't make me think) and it was talking about this - every page needs to have a very visual identifier where it tells the user exactly what the main purpose of this page is.

Perhaps you need to step back and look at your page design again - if there are similar containers on the page they can use H2 headings, but there should be a grouping around that somewhere (H1) that sums up the page's overall purpose to the user. I recently faced the same issue on the PokerDIY.com skin redesign and how to handle this.

Tom Kraak Tom Kraak says:

Well put Rod.

@ Ken - there is no need for a custom skin object. Just put this into your skin:

<%=PortalSettings.ActiveTab.TabName %>

Tom Kraak Tom Kraak says:

<%=PortalSettings.ActiveTab.TabName %>

Christian Christian says:

Any one knows if we can change the breadcrumb to display the page title and not the page name?

Vasilis Vasilis says:

@ Christian

<%=PortalSettings.ActiveTab.Title %> will give the page title if you put it in the skin code.

Now if you want to update the breadcrumb skin object you have to update the BreadCrumb.ascx.vb under \admin\Skins.

Vasilis Vasilis says:

<%=PortalSettings.ActiveTab.Title %>

bj bj says:

How come, when you set the Root Level to "-1", DNN shows an error?

bj bj says:

The above comment was in reference to when you try to "Write a Custom Skin Object".

bj bj says:

JavaScript hack doesn't work.

Vasilis Vasilis says:

@bj

use "0" for Root Level

bj bj says:

"-1" is what is allowing me to see.....Home > sub > sub.....right now with the last "sub" still linked.

When I use the "Write a Custom Skin Object" (to unlink the last sub) process and change the Root level to "0" I no longer see "Home" and when I leave it at "-1" I get a DNN error. Could it have something to do with setting in the Language Editor?

Vasilis Vasilis says:

@bj

Have you downloaded the skin object from the link in the post above?

There is a readme.txt file in there with information about what you need to do to use the skin object in the skin code.

bj bj says:

yes

bj bj says:

Look.......if "-1" equals "Root" (or "Home" in my case) then why doesn't it work? Anyone?

Vasilis Vasilis says:

@bj

I don't think "-1" is an option with this skin object.

Mitchel Sellers is the one who knows for sure.

bj bj says:

That seems to be the case. Thanks V. The other ones don't seem to work either. Any other suggestions?

J J says:

Thanks for the tip. I am wondering also how you can have the link to Home displayed in all instances of the breadcrumb.

Any ideas?

RegGFX RegGFX says:

Breadcrumb Control - how do i display just top level breadcrumb?

To illustraite. If the user visits a page called "Apples" and then selects a sub menu item of "Types of Apples" I would like the bread crumb of my skin to display only top level of "Apples" in the breadcrumb and NOT "Apples>Types of Apples"
So ...Is this possible?


Vasilis Vasilis says:

Vasilis Vasilis says:

< a href="<%=PortalSettings.ActiveTab.BreadCrumbs(0).FullUrl %>"><%=PortalSettings.ActiveTab.BreadCrumbs(0).TabName %>< /a>

RegGFX RegGFX says:

ok... forgive me if i asked a stupid question, but are you saying that just by putting a simple html href tag of < a href="">< /a> in the Custom Breadcrumb source code you provided will display only the Top Level root of the bread crumb?

Vitaly Vitaly says:

<a href="<%=PortalSettings.ActiveTab.BreadCrumbs(0).FullUrl %>"><%=PortalSettings.ActiveTab.BreadCrumbs(0).TabName %>< /a>

Vitaly Vitaly says:

That's what Vasilis wrote before - it just got chewed up in the innards...

Vasilis Vasilis says:

No, I meant that you can use the code I posted instead of the breadcumb skin object.

Seems that you can see the code I posted only in firefox.

Vitaly Vitaly says:

Oh, I was wondering why you didn't re-post... you can see it in FF but not in IE/CHrome, etc.

How bizarre is that?

Vasilis Vasilis says:

Yeah, weird...

Chip Chip says:

Tom,

Love this post. I am running into a little problem implementing fix #3 and was hoping you (or someone else) could help.

Not sure if it matters, but I am using DrNuke Flex2 skins which lets you customize your look. I installed your module and went to make changes to the ascx file, but nothing happened. According to my host settings, I am using the skin called Template-CustomBanner-01. Here are the two edits I made to its ascx file

EDIT #1:
Original {! - %@ Register TagPrefix="dnn" TagName="BREADCRUMB" Src="~/Admin/Skins/BreadCrumb.ascx" % }
NEW {! - %@ Register TagPrefix="dnn" TagName="SCBreadcrumb" Src="~/DesktopModules/SCBreadcrumb/SCBreadcrumb.ascx" %}

EDIT #2:
ORIGINAL {!-- dnn:BREADCRUMB runat="server" id="dnnBREADCRUMB" CssClass="BreadcrumbToken EMFontFamily" Separator="<span class="EMBaseColour4 BreadcrumbSpan"><img src="images/breadcrumb.png" alt="" class="trans-png" /></span>" RootLevel="0" /}
NEW {!-- dnn:SCBreadcrumb runat="server" id="dnnBreadcrumb" Separator=" » " CssClass="BreadcrumbToken EMFontFamily" RootLevel="0" /}

I don't care about using my template's fancy separator's - " » " is fine by me. I uploaded the new .ascx file, re-started DNN, and the breadcrumbs did not change.

Any help would be greatly appreciated. If this is not an easy fix, please let me know.

Thanks!
Chip

Vasilis Vasilis says:

@ Chip

I don't see anything wrong in your code... it should work fine.

Are you sure the ascx file you edited is the same with the one you're using on your site?

Rob Speksnijder Rob Speksnijder says:

Great post, one question.

I have 1200 pages on my site, and having found this blog would like to ask my developer to implement the third solution. Will they be able to implement it easily enough so it takes the link off the last item in the breadcrumb on all pages? Or is this something that they'll have to do to every page on the site?

Tom Kraak Tom Kraak says:

@ Rob - yes, once the skin object is properly installed and the skin files modified accordingly, it will take care of all breadcrumbs on all pages of your site.

Note though that this was written for DNN 4 and I have not been able to test it for DNN 5.

Let us know if you run into anything or have further questions.

Rob Speksnijder Rob Speksnijder says:

Many thanks Tom. One further question i do have on the DNN breadcrumb is the fact that the 'Home' link goes to my .co.uk/Home.aspx URL.

For SEO purposes i believe it would be better if it just went to my .co.uk/ address. How can i fix this?

Tom Kraak Tom Kraak says:

In my eyes there is no need to even have a breadcrumb on the home page ... for what?

But I do know what you are getting at. Modern search engines have become smart enough lately and now know that /default.aspx and /home.aspx are one and the same page. So I don't think it's as big an issue as it used to be, but you could still set up a 301 redirect back to /, which is what I did on this site. There are multiple ways to do this ... what's your hosting environment like? Shared or dedicated?

Rob Speksnijder Rob Speksnijder says:

Sorry to confuse Tom.

The 'home' link appears at the start of the breadcrumb trail on any page on the site (i agree its not needed on the homepage but dont know how to get rid of that either!).

Interesting you say its not such an issue these days, though Google Webmaster Tools are currently telling me its a duplicated title so i would still like to amend.

My hosting environment is shared.

Tom Kraak Tom Kraak says:

But you are not running the Seablick breadcrumb skin object on thebestgiftsaround.co.uk as discussed above, are you?

Andy Schmit Andy Schmit says:

Is there a way to have the breadcrumb module use default.aspx as the "home" link, rather than the home page of the DNN portal. In our case that is for SEO reasons, it would be preferable to have default.aspx be the link.

Any thoughts.

Thank you.

Kleber Kleber says:

it works on dnn 2.1.2?

Kleber Kleber says:

Ok, it works here.
now i'm searching how customize css style of element

Comments are closed

Subscribe to our Feeds Follow on Twitter