0

I'm using a child theme based on Theme Nectar's Salient WordPress theme, and I'm encountering a frustrating issue in attempting to modify the text that displays for a sticky nav sub-menu in a collapsed (mobile) state. After digging through the parent theme files, I'm seeing that the php code responsible for the submenu, located in a "nectar-vc-addons" sub-folder, is as follows:

echo '<a href="#" class="mobile-menu-link"><i class="salient-page-submenu-icon"></i>'.__('Menu',NECTAR_THEME_NAME).'</a><ul  style="background-color:'.$bg_color.'; color: '.$link_color.';" >'.do_shortcode($content).'</ul>';

This results, in part, in the following markup being generated for the menu:

<a href="#" class="mobile-menu-link">
    <i class="salient-page-submenu-icon"></i>
    "Menu"
</a>

All I want to do is change this "Menu" text to something different, and there doesn't appear to be a theme option to do so; and I'd like to avoid altering the PHP in the theme file so it's not overwritten in the event of a theme version upgrade.

I realize I can use some jQuery trickery to alter the string, but I'm wondering if there's some way I can change the text in the functions.php file in my child theme or some other way? I'm open to CSS approaches as well perhaps using psuedo elements, but I can't come up with anything that works in changing the text within the anchor element and keeping the icon. Any assistance here is greatly appreciated!

1

You can leverage the use of the gettext filter to change the text. Add this code to your child theme's functions.php or to a plugin:

add_filter('gettext', 'wpse248225_change_text', 20, 3 );
function wpse248225_change_text( $translated_text, $untranslated_text, $domain ) {
    if ( NECTAR_THEME_NAME !== $domain ) {
        return $translated_text;        
    }

    // Make the changes to the text
    switch( $untranslated_text ) {
            // Change 'Menu' text
            case 'Menu':
                $translated_text = __( 'something different', 'text_domain' );
            break;

            // add more items
     }

    return $translated_text;        
}
  • Wow, that is exactly what I was looking for, thank you, Dave! Works like a charm. One question-- why the name wpse248225_change_text? – nickpish Dec 3 '16 at 22:58
  • Awesome, you got it! That is just a naming convention used here on WPSE so that functions have a unique name. It's just wpse_ + {question ID (from URL)}. You can safely replace that with your own prefix and replace text_domain with your own text domain string too. – Dave Romsey Dec 3 '16 at 23:01
  • Ah, got it-- makes sense; I will keep that in mind for the future on this forum! Last question-- what is the purpose of the text_domain portion? – nickpish Dec 3 '16 at 23:05
  • 1
    That's just a unique identifier. Each plugin and theme should use its own unique text domain string. It allows for specific targeting of strings, such as in the example I posted. We just targeted the string Menu for the NECTAR_THEME_NAME text domain. (Side note, your parent theme is going against the guidelines by using a constant for the text domain; it should be a string.) More on translation stuff here. – Dave Romsey Dec 3 '16 at 23:10
  • Got it, thanks so much for the explanation, Dave. It's also not surprising that the parent theme is going against the guidelines-- I think it's crazy the "Menu" string is effectively hardcoded into the theme component this way in the first place. – nickpish Dec 3 '16 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.