• Hi there. I would like to make it so that all the vowels in my wp_nav_menu change color on mouseover. To do this, I’ll wrap each vowel in a <span> tag, and use CSS for the rest. Yes, I know this is a peculiar thing to want to do. So, I’m trying to write a filter:

    function str_replace_assoc(array $replace, $subject) {
       return str_ireplace(array_keys($replace), array_values($replace), $subject);
    } 
    
    function title_wrap_vowels($title) {
    
    $vowelreplace = array(
    'a' => '<span>a</span>',
    'e' => '<span>e</span>',
    'i' => '<span>i</span>',
    'o' => '<span>o</span>',
    'u' => '<span>u</span>',
    );
    
    return str_replace_assoc($vowelreplace, $title);
    }
    add_filter('the_title','title_wrap_vowels');

    This works perfectly, except obviously, it replaces the_title EVERYWHERE (in the backend, in the <title> meta tag, I mean EVERYWHERE).

    So is it possible to only apply the filter to the_title as used in wp_nav_menu?

    Thanks –

    Steve

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘add_filter to the_title only in wp_nav_menu’ is closed to new replies.