Skip to content

Language and Text Direction in WP 2.1

January 16, 2007
by Ryan Boren

WordPress 2.1 introduces a new template function called language_attributes(). This function can be used to add lang, xml:lang and dir attributes to the html tag of your theme.

<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

If your locale is currently set to “en”, the result looks like this:

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

If you are using a right-to-left language like Farsi, the output looks like this:

<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl" lang="fa" xml:lang="fa">

To get the language and direction individually, use get_bloginfo().


$direction = get_bloginfo('text_direction');
$language = get_bloginfo('language');

language_attributes() is in 2.1 only, so adding it to your theme will make it incompatible with 2.0.x unless you take special precautions. Once 2.1 is out, this might be backported to 2.0.x.

13 Comments
  1. January 16, 2007 7:47 pm

    Nice. For those of us using a blog that is in a language that reads right to left, I could see this being very useful.

    Also very useful in a way of bringing WordPress even further beyond the rest of the blogging systems out there.

  2. January 16, 2007 10:11 pm

    Great edition Ryan,

    Any suggestions on how to differentiate between 2.1 and 2.0.x in order to ensure the theme works for both versions?

  3. January 17, 2007 3:36 am

    I probably wont personally use it, but it’s a great leap forward in terms of accessibility that the team should be proud of. It might encourage some bloggers in other languages to use wordpress, too.

  4. January 17, 2007 9:19 am

    I do agree with Matt. this will put WordPress far beyond not only the current blogging systems but also all the web applications which simply ignored right to left languages and localization in general.
    Localization is not simply translating the phrases and I am really delighted to see wordpress is proving it in action. Thanks to Ryan, Matt and Mani.

  5. January 17, 2007 12:05 pm

    this is NOT “Farsi language”, this is “Persian language” ;)

  6. January 17, 2007 12:25 pm

    I’m glad you’ve finally taken steps to help RTL language bloggers.
    The Hebrew WordPress community is still growing slowly with our own adaptions.
    I would however, like to try this version and the new RTL features. I’m not sure how much impact this has, because directionality is not enough; themes need to be carefully fitted to RTL, with additions such as {text-align:right;) etc.
    What else does this affect?

  7. January 17, 2007 12:29 pm

    Also, I think a better thing to do, would be to set that if the directionality is RTL, WordPress should load “stylertl.css” instead the normal packages. That’s in case you would like to display the RTL abilities with English, international WordPress installation out of the box.
    I hope you’re catching my drift.
    I’ve seen it working wonderfully on LifeType and I’m sure it can be done on WP.

  8. January 17, 2007 1:49 pm

    Ryan, are those get_bloginfo() arguments new ones for 2.1? I’m just wondering what I can do to improve the situation for blogs running (and still running, once 2.1 comes out) 2.0.x that improves on just leaving my theme with xml:lang="en" lang="en" in as the default.

  9. January 23, 2007 12:01 am

    Ajay use:

    if ( function_exists(‘language_attributes’) ) { language_attributes(); }

Trackbacks

  1. Wordpress 2.1 Beta 4 | aNieto2K
  2. Testing, 1-2-3, Testing · plaintxt.org
  3. Glossika » Blog Archive » Language and Text Direction in Blogs
  4. » WP v2.1 template tags change log TawnyGirlGrafix Adult Web Design

Comments are closed.