Progress Report – Tab Linking

One of the requested features for Arconix-shortcodes v1.0 was to add the ability to link to a specific tab of a tab group. While it seemed easy enough, there were a couple things to keep in mind, and I thought it’d represent a good opportunity share the though process behind choosing the default behavior I did.

The links are achieved through anchor tags. Anchor tags are commonly used for linking to specific sections on a web page. For example, anytime a link is clicked and the browser jumps to a point further down the page, that is achieved through an anchor tag. The browser’s address bar would reflect that link, displaying something like “#section-title” at the end of the address.

I rewrote sections of the [ tabs ] shortcode to accept this functionality and added an additional parameter id. In configuring the default option for id, I was presented with 2 options.

  1. Loop through all the tabs and assign each tab an incrementing number (i.e. tab-1, tab-2, etc…)
  2. Assign each tab’s id based on the tab’s title (i.e. tab-my-tab-title, tab-product-specs).

There were pros and cons to each approach. Assigning each tab an incrementing number kept things short, simple and allowed the user to change the title without breaking the links. The downside is that if the user had multiple tab groups on a page, linking would essentially break because there would be multiple tab-1 instances, etc.. Assigning tab ids by name is a little lengthier and the links would break if the tab’s title was changed after the link was created, but unless there were multiple tabs with the same name, the linking wouldn’t break.

Due to the potential for breaking the links with multiple tab-1’s, I decided to default to assigning the id based on tab’s name. I didn’t eliminate the tab number option however as that is still an attractive alternative in those instances where the user knows only a single tab group will exist on each page.

I added to my plugin the following switch statement for that.

If id=”number” is used, then the code will increment each tab by 1 and assign it as the ID. If id=”name” or is ignored, then it will assign the sanitized title.

I’m just wrapping up testing on v1.0. Once that’s completed, I’ll update the wiki and release the plugin. Barring any major issues, the release should happen before the end of the month.