What does l10n.js do in WordPress 3.1? And how do I remove it?

The question:

I just installed WP 3.1 Beta 2 on my test server. I noticed that it ships with a new l10n.js file that gets automatically inserted into the header.

I did a bit of digging and it has something to do with localization. I’m guessing that many people don’t use this, so I’m wondering how I could remove it?

If it’s important not to remove it, please let me know as well.

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

It contains the convertEntities() function that (as the name says) converts HTML entities to their actual value. It is mostly used for scripts that send over localization data from PHP to the JS side using wp_localize_script(). Just search for l10n_print_after in the code base and you see it a lot.

The data you add in wp_localize_script() is added before the script it translates (it must be, because it is referenced there). However, if you use a script concatenator (so you only have one request that returns all used JS files), this one file would also be called after all localized data – but now convertEntities() is not defined when we need it. For this reason this function is split off the general utils.js file and added with a high priority at the top.

For this reason you should not remove it: all scripts that use translatable strings use it (even if they are still in English), and you might break places that still have entities.

Method 2

if ( !is_admin() ) {
function my_init_method() {
wp_deregister_script( 'l10n' );
add_action('init', 'my_init_method'); 

use the code above to deregister l10n.js in function.php

Method 3

Looks like it is included when you enqueue the ‘comment-reply’ scrip. Note that you probably want to make sure ‘comment-reply’ is loaded only on pages could have comments enabled (e.g. check is_singular() before enqueueing the script).

Method 4

I found on my installation that this script was loaded alongside the new admin bar, getting rid of the admin bar got rid of the l10n.js for me(but i think Jan’s answer is more inline with answering the “why”).

Removing the bar was easy..

remove_action( 'init', 'wp_admin_bar_init' );

This doesn’t actually address the question(as evidenced by the other answers), but incase anyone wants to remove that awful bar, the above is how you do it..

Method 5

How to remove it:

function kill_l10n() {
    if ( !is_admin() )
        wp_deregister_script( 'l10n' );
add_action( 'wp_print_scripts', 'kill_l10n' );

Drop in functions.php or whatever (plugin, etc.)

Works for me.

Method 6

To remove it add the following to your theme’s functions.php file.


Method 7

Developers source for the file has following description:

//Used to ensure that Entities used in L10N strings are correct

and commit note says:

Move the l10n helper function into a seperate js file so we can always output it first.

I hadn’t played with 3.1 yet so not sure what can make it load in every page.

Method 8

Yep it’s thrown inside the theme by wp_head automatically…
I remove it by placing the code below in the theme’s functions.php

remove_action( 'wp_head', 'l10n' );

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment