AZIndex LogoAZIndex version 0.5.3 has just be released.  It’s just another interim version as I am gearing up for my summer vacation, mainly to fix a bug where the sorting of the headings was case-sensitive.  I’m not sure how that one escaped detection for so long!

I also took the opportunity to add a filter to the plugin — ‘azindex_heading’ — which, if set, will be called for every heading before the index is sorted.  This allows users to write a filter function that can modify the heading in ways that can’t currently be done using the AZIndex plugin — for example, if you want to strip words like “A”, “An” and “The” from the front of the heading then you can write a simple filter to do that.

Below is an example of such a filter.  It will remove “The”, “An” and “A” (of various cases) and put them at the end of the heading instead — e.g. “The Great Escape” will be transformed to “Great Escape, The”.  Useful for certain types of indexing:

add_filter('azindex_heading', 'my_filter_heading');                  

function my_filter_heading($heading) {
   if (preg_match('/
^(THE |The |the |AN |An |an |A |a )/', $heading)) {
       $split = explode(' ', $heading, 2);
       $heading = $split[1].
', '.$split[0];
   return $heading;

Note that this is just an example and there may be a more correct way to do the same thing, but it works as advertised.  You can add your filter function to the functions.php file in your current theme.  Remember to clear the index cache (from the AZIndexes admin page) once you’ve added the filter so that the altered headings will be sorted in the correct order.

If anyone comes up with a useful filter function of their own, please feel free to post it here.