Category Base Rename Is Inconsistent (PART 2)
-
In a previous topic I lamented that a renamed category base did not reflect the change in category archive page headings. @alchymyth replied with a perfect solution….though a solution that, twenty months later, I cannot successfully modify.
Michael’s first if block was fine, but I’d like to customize further by assigning a unique label to each category archive.
This code will not work. I have been able to accomplish almost the same end by pattern matching against $title, but going forward it would be better if matched against category. I’ve tried various other work-arounds like iterating the category array into a string. I just can’t seem to figure this out. PHP is not my forte; I’m a Perl guy (yes, I know PHP morphed out of Perl, but I find PHP inordinately more obtuse than Perl).
function use_category_base_in_archive_title( $title ) {if ( is_category() && get_option('category_base') ) $title = str_replace( 'Category:', ucfirst( get_option('category_base') ) . ':', $title ); elseif ( is_category() && preg_match("/English/i", get_the_category()) ) $title = str_replace( 'Category:', 'Language:', $title ); elseif ( is_category() && preg_match("/Spanish|Español/i", get_the_category()) ) $title = str_replace( 'Category:', 'Idioma:', $title ); elseif ( is_category() && preg_match("/French|Français/i", get_the_category()) ) $title = str_replace( 'Category:', 'Langue:', $title ); elseif ( is_category() && preg_match("/Latine?/i", get_the_category()) ) $title = str_replace( 'Category:', 'Lingua:', $title ); return $title; } add_filter( 'get_the_archive_title', 'use_category_base_in_archive_title' );
- This topic was modified 5 years, 1 month ago by .
- This topic was modified 5 years, 1 month ago by . Reason: added note about successfully matching against $title
The page I need help with: [log in to see the link]
- The topic ‘Category Base Rename Is Inconsistent (PART 2)’ is closed to new replies.