Hi,
The best way to ignore the first character is to use the a_z_listing_item_index_letter
filter. This can be added to your theme or child-theme’s functions.php
and will ignore any non-alphabetical letter:
add_filter( 'a_z_listing_item_index_letter', 'ignore_a_z_non_alphabetical_letters_at_start_of_title', 10, 3 );
function ignore_a_z_non_alphabetical_letters_at_start_of_title( $index_letters, $item, $type ) {
// if we already have an alphabetical letter, return it immediately
if ( preg_match( '/^[A-Za-z]$/', $index_letters[0] ) ) {
retrun $index_letters;
}
// loop through the title letters and return the first alphabetical letter
for ( $i = 0; $i < mb_strlen( $item->title ); $i++ ) {
$letter = mb_substr( $i, 1 );
if ( preg_match( '/^[A-Za-z]$/' $letter ) ) {
return array( $letter );
}
}
// if we get here, then there are no alphabetical letters in the title so return the original index
return $index_letters;
}
-
This reply was modified 4 years, 1 month ago by Dani Llewellyn. Reason: add missing regex `//` characters