• Resolved javfuller

    (@javfuller)


    Using version 1.10, I get a javascript error that _ variable is undefined which comes from lib/class-option-number.php (line 123).

    Seems it’s using the _ variable, but it’s undefined. This causes my Yoast SEO plugin to break. I can’t edit the Titles & Metas settings in the admin.

    New behavior with 1.10. Did not happen with 1.9.x and prior.

    Specific to using a number field.

    Offending code in lib/class-option-number.php (line 123):
    $( ‘.tf-number input[type=number]’ ).on( ‘keyup’, _.debounce( function() {
    if ( $( this ).prev().slider( ‘value’ ).toString() !== $( this ).val().toString() ) {
    $( this ).prev().slider( ‘value’, $( this ).val() );
    }
    }, 500 ) );

    I had to install the underscore.js library from underscorejs.org and that defined _ and _.debounce().

    It seems version 1.10 code was developed with this or a similar library, but that library is not included anywhere in the code.

    1.9.x and before didn’t have this code, it’s new to 1.10. Options are to remove the _.debounce function that wraps the anonymous function or install a library that defines _ variable and the debounce function.

    Any word on when titan will either change/fix this code or include the necessary library?

Viewing 7 replies - 1 through 7 (of 7 total)
  • I do no have Yoast SEO installed but facing exactly the same issue. In my case I’m not able to create custom menus or manage widgets in admin area.

    @javfuller how did you install underscore.js? I downloaded it from the website as you suggested and copy it into \wp-content\plugins\titan-framework\js, but error persists. Am I missing something?

    UPDATE: I enqueued underscore.js script via functions.php but the error still exists. Any ideas?

    • This reply was modified 8 years, 4 months ago by Viko885.
    Thread Starter javfuller

    (@javfuller)

    Yoast is just a symptom. The problem can show itself in any number of other ways.

    But to to answer your question, I added the underscore.js to my theme and enqueued it from the function.php.

    Since your problem continues, I would double check the error on your page. The error I was getting was that _ was undefined. Check Firebug or Web Inspector in other browsers for javascript errors.

    What errors are you getting? Do you have a link we can look at?

    Hi and thanks for the reply.

    I’m getting the error:

    ReferenceError: _ is not defined
    $( '.tf-number input[type=number]' ).on( 'keyup', _.debounce( function() {

    I realised I do not need to enqueue underscore.js as it is already included in my theme.
    <script type="text/javascript" src="https://www.myweb.sk/wp-content/themes/pbs-theme/js/underscore-min.js?ver=1.0.0">

    If you need to look into admin area on my site please let me know how can I forward login credentials to you safely.

    Many thanks

    Thread Starter javfuller

    (@javfuller)

    I’m getting a 404 when trying to get to the js file. Make sure it’s actually there and readable. Check your file permissions and paths.

    I also get a 403 when I to go to https://www.myweb.sk.

    If you want to create temporary credentials, send them through my contact page: https://www.fuller-online.com/contact-us

    Sorry, I changed my site’s name to avoid spam. I sent you an email. Thanks for looking into it.

    Thread Starter javfuller

    (@javfuller)

    I don’t see the js file in your current theme. Make sure that it is there, and make sure that you enqueue it for the admin side of the site using the admin_enqueue_scripts hook.

    function fos_enqueue_style() {
    wp_enqueue_script( ‘lib-underscore’, get_stylesheet_directory_uri().’/js/underscore-min.js’);
    }

    /* call the enqueueing function for the admin end of the site */
    add_action( ‘admin_enqueue_scripts’, ‘ fos_enqueue_style’ );

    Thanks for the patience Javier you’re the star. It works!

    I enqueued the JS file as you suggested and admin pages are back to normal again.

    function fos_enqueue_style() {
    		wp_enqueue_script( 'underscore', get_stylesheet_directory_uri().'/js/underscore-min.js');
    	}
    add_action( 'admin_enqueue_scripts', 'fos_enqueue_style' );
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘_ undefined variable; missing library; causes Yoast SEO to break’ is closed to new replies.