Many WordPress sites include navigation menus generated using the wp_list_pages() function. By default, wp_list_pages() links to pages using page titles as the link text, but sometimes it’s useful to link to a page using something other than its title. For example, the title of this website’s home page is “Welcome to Technokinetics”, but I’d much rather have it linked to as “Home” in the top navigation menu.
This is a common enough scenario that I thought it would be worth writing a plugin to make it easier to deal with. The result, Alt Link Text, adds an “Alternative Link Text” field to the Write Page and Manage Page screens in the WordPress dashboard. This field can be used to specify alternative link text to be used in place of the page title in page lists generated using wp_list_pages().
The plugin also adds an “Alternative Title Attribute” field, which can be used to specify a title attribute to be used in place of the page title in page lists generated using wp_list_pages().
The plugin will work with WordPress versions 2.5 and upwards. It will not work with earlier versions of WordPress, as the functions that it uses were only added in version 2.5.
To use the plugin:
- Download Alt-Link-Text, extract the contents, and upload them to your wp-content/plugins folder.
- Login to your WordPress dashboard, click ”Plugins”, and activate Alt Link Text.
- Set the alternative link text and title attribute that you’d like to use through the Write Page or Manage Page screens. You will need to save the page for the changes to take effect.
October 11th, 2008 at 11:20 am
Just a quick note about recent releases.
Yesterday I released v1.0 via the offical WordPress plugin database. This version included a new feature, a checkbox on the Write Page and Manage Page screens that lets you exclude pages from your page lists.
This morning I realised that by default new pages were being excluded from page lists, which meant that to create a page and include it in your menus you now had to remember to check a box that you didn’t have to check before.
This was the opposite of user-friendly, so this morning I rushed out v1.0.1, which includes new pages in page lists by default. If you’re one of the eight people who downloaded the irritating version of the plugin, I apologise (and suggest you upgrade)!
Please also note that if you upgrade to v1.x from any v0.x, then you’ll need to deactivate and reactivate the plugin (otherwise you’ll get error messages caused by a missing database table column).
That’s all for now. I hope you’ll find the plugin useful.
October 16th, 2008 at 7:53 am
When the original title of the page contains brackets e.g. () the original page title is used rather than the alt title text.
For example, I have a page called “About the Emotional Freedom Technique EFT” and alt title text of “About EFT”. This works fine. But If I now change the page title to “About the Emotional Freedom Technique (EFT)” and leave the alt title text as “About EFT”, in wp_page_lists the title is now shown as “About the Emotional Freedom Techniqe (EFT)” rather than the alt text.
October 16th, 2008 at 8:22 am
Simple fix is to use the basic str_replace in the two replacements so as not to get into trouble with regular expressions e.g.
$output = str_replace(’>’ . $post_title . ” . $alt_link_text . ‘<’, $output);
October 16th, 2008 at 9:42 am
Thanks Rod. The first official release of Page Lists Plus will use str_replace in place of preg_replace, so this problem shouldn’t arise from then on.
October 16th, 2008 at 11:26 am
Right, Page Lists Plus is now completely str_replace based (well, nearly), and does everything that Alt Link Text ever did and more, so I’d suggest switching to that.
Thanks again to Rod for the input.