0

I am creating multilingual website in Urdu & English lanugage on Wordpress. Major part of site is in English. Only article's body (i.e paragraph & headings etc) are in Urdu. To assign Urdu fonts to urdu content, when writing article, I just switch to HTML Mode and insert lang="ur" attribute with elements and style them in CSS by :lang() pseudo selector.

Now I get problem that how I can specifie lang attribute for Post/Page title? Any idea?

I hope you will understand what I want to say. Thanks

1

There is a the_title filter. You should be able to wrap the title in a <span> using that.

add_filter( 
  'the_title', 
  function($title) {
    return '<span lang="ur">'.$title.'</span>';
  }
);

A version compatible with an older PHP:

function lang_attr_wpse_116733($title) {
  return '<span lang="ur">'.$title.'</span>';
}
add_filter('the_title','lang_attr_wpse_116733');

If it were me, I'd add a checkbox on the post edit screen somewhere and then wrap both the title and the post body with a <span> or <div> based on that single checkbox.

  • Thank you for answer but above code is not working. I get this error: "Parse error: syntax error, unexpected T_FUNCTION in /home1/tissosas/public_html/asanpaisa.com/wp-content/themes/academy/functions.php on line 52" What is wrong? Please describe more. I am new to java. Thanks – John Doe Oct 4 '13 at 14:31
  • @JohnTossot : I think you are running an older PHP. See the edit. – s_ha_dum Oct 4 '13 at 14:36
  • Thank you its working. But how I can add checkbox to my widget to make one click lang attribute addition as you give idea in you answer? – John Doe Oct 4 '13 at 14:42
  • Sorry? That last comment contains the first mention of "widget" I've seen in this question? Second, you aren't dealing with "java". This is PHP. Third, I didn't elaborate about the checkbox because it isn't really part of the question and the solution would be rather long. Search this site for questions about adding meta boxes and see if you can't get started. – s_ha_dum Oct 4 '13 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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