Programmatically Set English as Default Language for Nodes in Drupal 7

Choose English In Drupal 7

A little bit of javascript is all you need


If you have a multilingual Drupal 7 site and are looking for a way to make the default language choice English (or other) rather than Language Neutral, you can use this small snippet to make that happen:

function mytheme_form_alter(&$form, &$form_state, $form_id) {    
    // Set default language to English 
    if(strrpos($form_id,'_node_form')) {
        if(isset($form['language']) && $form['language']['#value'] == 'und') {
            $script = "<script type=\"text/javascript\">
            var l = document.getElementById('edit-language');
            if(l.value == 'und') l.value = 'en';
            $form['some_text'] = array( '#markup' => $script );

Simply add the above to your template.php (and replace mytheme with your theme name).


Last updated on