ClockInfo.com
Commentary about clock repair and clock history from Bill’s Clockworks and ClockHistory.com

ClockInfo.com

Removing Menu Links to the Current Page

November 30, 2007 . by Bill

One of the fundamental usability guidelines is: never have a link that points to the current page – this confuses the user. (See Jakob Neilsen’s The Ten Most Violated Homepage Design Guidelines, guideline no. 10.) The WordPress blogs and websites that I have seen (including this blog!) violate this guideline in several ways. It would be nice if a future version of WordPress would give these functions an option to not link to the current page or category. In the meantime, I have written a plugin that strips the link to the current page. It is used on the web site for my church which is under development.

Here is the code for the plugin, I named the file rm_cur_menu_link.php. It is installed in the wp-content/plugins directory, then it may be activated in the plugin administration screen. This plugin will rermove self links in menus that are generated by the wp_list_pages() and wp_list_categories() functions.

<?php
/*
Plugin Name: Remove Current Menu Link
Plugin URI: Does not exist yet
Description: Removes link to the current item from a menu generated by wp_list_pages and wp_list_categories. This makes a WordPress website or blog comply with the usability guidelines that a web page should not have a link to itself.
Version: 1.0
Author: Bill Stoddard
Author URI: http://clockinfo.com/
*/

/* Copyright 2007 Bill Stoddard (email : bill@billsclockworks.com)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

/**************************************

Hooks and configuration

***************************************/
add_filter(‘wp_list_pages’,'list_pages_filter’);
add_action(‘wp_list_categories’, ‘list_categories_filter’);

function list_pages_filter($content) {
/* for some reason it would not work with [:blank:]* after the m in current_page_item */
return eregi_replace(‘(current_page_item “><a [^<]*href=["|\']?([^ "\']*)["|\']?[^>]*>([^<]*)</a>)’,'current_page_item”>\\3′, $content);
}

function list_categories_filter($content) {
return eregi_replace(‘(current-cat[:blank:]*”><a [^<]*href=["|\']?([^ "\']*)["|\']?[^>]*>([^<]*)</a>)’,'”>\\3′, $content);
}

?>

I still consider this plugin to be experimental, although it works fine in my application (WordPress version 2.3.1), so I have not released it as a downloadable plugin yet. You can see it in action on the Flora First Christian Church website.

I thank silisoftware.com and xce.de for their helpful comments on the eregi_replace manual page.

Post to Twitter

Related posts:

  1. Removing the Self Links on the Home Page
  2. Creating a Web Site for My Church
  3. Setting up WordPress
  4. WordPress Permalink Format
  5. Modifying WP PageNavi Plugin
  6. Embedding a YouTube Video in WordPress

5 Responses to “Removing Menu Links to the Current Page”


  1. [...] Unfortunately it’s pretty hard to find anything on the subject for solving the problem in your CMS’s or blogs. There was only one reference I could find in trying to resolve the issue in the blogging/CMS application, WordPress: Removing Menu Links to the Current Page [...]

  2. comment number 2 by: Bob

    Links to pages that the user is actually reading is annoying, if not entirely daft (it’s a pet hate). For those that are serious about accessibility, this is a must-have for WP. (pls) Consider putting it out as a plug-in as I’m sure it will be useful, if not improved over time. Good work.

  3. comment number 3 by: Dusty

    Not working as of WordPress 2.7. The error received is: Parse error: syntax error, unexpected T_STRING in (*server path*) on line 38.

  4. comment number 4 by: Frank P

    Yeah, this should really be sorted out in WordPress – analytics shows that a LOT of visitors click the link to the page their on.

    Love to see a fully functional plugin for this.

  5. comment number 5 by: sandrar

    Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

Leave a Reply

Name

e-Mail (will not be published)

Website