add_filter to the_title only in wp_nav_menu (2 posts)

  1. stevecoy
    Posted 5 years ago #

    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);

    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 -


  2. stevecoy
    Posted 5 years ago #

    HA! I figured it out. Here it is in pastebin:


Topic Closed

This topic has been closed to new replies.

About this Topic