• It’s me again ??

    I noticed that I cannot use translates ( _e() or __() ) in the functions.php. Is that a bug always for me an is there a way to make it work?
    Atm I am playing the functions at the top of my header.php but I would like to change that. Especially now when I am using wp_localize_script() that is placed in my functions.php together with the scripts …

    https://www.ads-software.com/plugins/loco-translate/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tim W

    (@timwhitlock)

    “cannot use” – in what way can you not use them?

    Loco looks for both these functions when extracting strings from your files.

    Thread Starter Insomnia88

    (@insomnia88)

    When I have a function that returns a variable filled with __('test message', 'bla) for example.

    Or with wp_localize_script()

    wp_enqueue_script( 'my-script', get_template_directory_uri() . '/js/script.js', array( 'jquery' ), null, true );
    wp_localize_script('my-script', 'translate', array(
                'not_required'  => __('not required', 'bla')
    ));

    it returns “undefined” in my script then. And yeah, the code itself is working. I can hardcode strings in my functions.php or in wp_localize_script that will returned like they should. Seems like the translation is not done when the functions in functions.php are fired.. I can place it at the very top or the bottom of the file.

    Plugin Author Tim W

    (@timwhitlock)

    I can only offer support for the Loco Translate plugin. I don’t think your query is related. Please ask for help in a general WordPress forum.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘no functionality in functions.php ?’ is closed to new replies.