Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am doing a worpdress theme which is in Arabic language. When I write anything in Arabic. It turn into ????(question mark).

Please help to fix this.

Thanks

share|improve this question
    
Do you mean your Arabic text in your browser turns into questions marks? Or is it in your editor? Please explain. –  Greeso Aug 3 '13 at 20:38
    
When I write text under Dreamweaver it shows Arabic text and once I check it in any browser it turn into ????? –  Hussain Ansari Aug 3 '13 at 20:41
1  
OK, read my answer below. Also stop using Dreamweaver, it is deprecated. Switch to either Eclipse or Notepadd++ (both are free) or any other editor that is still supported. –  Greeso Aug 3 '13 at 20:56

3 Answers 3

  1. Make sure all your files are encoded in UTF-8.
  2. Keep your theme language agnostic: Write all strings in English and use the proper translation functions to get the translated string (eg. Arabic):

    _e( 'Hello world!', 'your_text_domain' );
    
share|improve this answer
  1. Files should be Encoded in UTF-8, this can be verified with your text editor
  2. Add a charset meta tag: <meta charset="<?php bloginfo("charset");?>" />

You shouldn't touch any php files in regards to this problem, the only time when you will do it is when you set the language for the blog, like this:

define ('WPLANG', 'ar');
share|improve this answer

In wp-config.php, make sure you have the following line (this is for the database, but it helps ensure everything is consistent):

define('DB_CHARSET', 'utf8');

Also you may want to switch your UI to arabic (however this is optional), but to do that, you can do change your language line in wp-admin to the following:

define( 'WPLANG', 'ar' );

Next, add the following code to appear in all your pages, a recommended spot of it is header.php

<!DOCTYPE html>

<html  <?php language_attributes(); ?>>
    <head>
        <meta charset="<?php bloginfo("charset") ?>">

        <!-- The rest of your code goes here -->
share|improve this answer
    
<meta charset> is useless (too late) and should not be used. WordPress will always send proper HTTP header, and those will win anyway. –  toscho Aug 3 '13 at 21:06
    
I am not sure about that. I set it in my environment this way, and it is working right. This will generate an HTML output that will be rendered by the browser. The browser has no idea if WordPress is used or not, all it cares is the final HTML. The brwoser is where he is having the problem and therefore this might not be as usless as you think. –  Greeso Aug 3 '13 at 22:04
    
The browser has already had to make a decision about the encoding just to be able to read that element. This decision is made by the HTTP headers. This is also the reason why you cannot 100% on Google pagespeed with the tag. –  toscho Aug 3 '13 at 22:28
    
You have to ensure utf8 is set properly. because the header files that PHP send use that char set, here is an example: @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );. That said, sending meta should still be used, meta informs whoever uses it (whether it is a browser or another tool such as Google pagespeed) that this page claims to be a utf8, and therefore, it will be useful for other purposes. –  Greeso Aug 3 '13 at 22:49
    
No, it doesn’t. The HTTP header declares the encoding, <meta> is completely irrelevant then. It is an old myth dating back to the times when people thought the server could parse the HTML file to detect the encoding. –  toscho Aug 3 '13 at 23:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.