Make WordPress Core

Opened 2 weeks ago

Last modified 6 days ago

#44494 new feature request

Add option to hide en_US in wp_dropdown_languages()

Reported by: swissspidy Owned by:
Milestone: 5.0 Priority: normal
Severity: normal Version:
Component: I18N Keywords: has-patch needs-testing needs-refresh
Focuses: Cc:


While working on the Preferred Languages project I noticed that it's not possible to hide the English (United States) option in wp_dropdown_languages().

In my case, I do not need the en_US because of the way the UI works: When I do not pick a language from the dropdown, en_US will be the default. Screenshot: https://cloudup.com/cXhxw4KPqFc

While I added a workaround using JavaScript, I think there should be a) a show_option_en_US parameter or b) a filter (e.g. $output = apply_filters( 'wp_dropdown_languages', $output, $languages, $parsed_args )) at the end of the function. Or perhaps even both.

Attachments (1)

44494.diff (1005 bytes) - added by danieltj 2 weeks ago.

Download all attachments as: .zip

Change History (5)

#1 @danieltj
2 weeks ago

wp_dropdown_languages() already supports $args so I'm in favour of supporting another argument in that array to exclude certain locales by slug or something.

languages is also already supported though; I suppose you could reverse engineer it so you get the full list list of locales, then remove en_US and then use the updated list (minus en_US) to request as those specific locales. Not ideal, but serves as a better work around than JavaScript perhaps.

Ref: https://developer.wordpress.org/reference/functions/wp_dropdown_languages/

2 weeks ago

#2 @danieltj
2 weeks ago

  • Keywords has-patch needs-testing added; needs-patch good-first-bug removed
  • Type changed from defect (bug) to feature request

I've changed the ticket type to feature as it's not really a bug as nothing is broken here.

I've added a patch which adds an extra argument for en_US. Simple, but does the job.

#3 @Luciano Croce
2 weeks ago

Great, I agree this!

#4 @swissspidy
6 days ago

  • Keywords needs-refresh added
  • Milestone changed from Awaiting Review to 5.0

Needs updated docs and probably an other name (I'd really use show_option_... for consistency), otherwise 👍

Note: See TracTickets for help on using tickets.