Meta tag language

Hello,

I am using wordpess english version to publish articles in arabic language.
How can i put this code in header.php of the child theme?
Any idea or you will tell out of scope. Yoast plugin has no input for that.

<html lang="ar"> Header Content-Language: ar

Thx

Hi There,

Please create_base.php file to this directory in your child theme x-child/framework/views/header/ with the following code:

<?php

// =============================================================================
// VIEWS/HEADER/BASE.PHP
// -----------------------------------------------------------------------------
// Declares the DOCTYPE for the site, includes the <head>, opens the <body>
// element as well as the .x-root <div> and .x-site <div>.
// =============================================================================

$x_root_atts = x_atts( apply_filters( 'x_root_atts', array( 'id' => 'x-root', 'class' => 'x-root' ) ) );
$x_site_atts = x_atts( apply_filters( 'x_site_atts', array( 'id' => 'x-site', 'class' => 'x-site site' ) ) );

?>

<!DOCTYPE html>

<html class="no-js" lang="ar">

<head>
  <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

  <div <?php echo $x_root_atts; ?>>

    <?php do_action( 'x_before_site_begin' ); ?>

    <div <?php echo $x_site_atts; ?>>

    <?php do_action( 'x_after_site_begin' ); ?>

Hope it helps :slight_smile:

It works,

`<?php

// =============================================================================
// VIEWS/HEADER/BASE.PHP
// -----------------------------------------------------------------------------
// Declares the DOCTYPE for the site, includes the , opens the
// element as well as the .x-root

and .x-site
.
// =============================================================================

$x_root_atts = x_atts( apply_filters( ‘x_root_atts’, array( ‘id’ => ‘x-root’, ‘class’ => ‘x-root’ ) ) );
$x_site_atts = x_atts( apply_filters( ‘x_site_atts’, array( ‘id’ => ‘x-site’, ‘class’ => ‘x-site site’ ) ) );

?>

<?php wp_head(); ?> >
>
<?php do_action( 'x_before_site_begin' ); ?>

<div <?php echo $x_site_atts; ?>>

<?php do_action( 'x_after_site_begin' ); ?>`

Happy to have this change.

Last thing: How can i add a second language “English”. Because my website is bi-language.

Thx

Hi There,

You should be able to utilize this WordPress function.

language_attributes();

For example:
<html <?php language_attributes(); ?>>

More information (https://codex.wordpress.org/Function_Reference/language_attributes).

Thanks!

Hi,

I have an issue now with my subfolder https://tarekrabaa.com/en. which has been affected by the change of language to ar.
This subfolder i want it in english.
The one in Arabic is https://tarekrabaa.com and https://tarekrabaa.com/en i needed it in English lang En-US.

I tried to replace the code <html class="no-js" <?php language_attributes(); ?>> in the main PRO/framework/views/header by <html class="no-js" lang="ar"> and to replace the header i added in the child theme by <html class="no-js" lang="en">
I got this for the https://tarekrabaa.com `

` and this for english subfolder https://tarekrabaa.com/en/ ` ` Can i do this? or in case of 2 languages defines i need to add a langugae attribute for each post or page? I tried plugin polylang i got fatal error. I removed it.

I configured my Arabic website with rtl and if i change the setting languges to Arabic in Wordpress i will loose many customization.
plz any solution to have arabic meta lang and English meta lang while keeping Wordpress backend in English LTR for both main site and its subfolder?

thx

Hi There,

Do you have separate WordPress installations for different languages? If so you can manually set those values by editing _base.php file.

If you’re using a plugin like WPML, the above function language_attributes(); should work.

However you cannot set multiple languages as it will be not supported by W3C standards.
<html class="no-js" lang="ar,en">

For more information, please go through (https://www.w3.org/International/questions/qa-html-language-declarations).

Thanks!

Thx.

I am using Wordpress from which i added my english subfolder whihc is for english language only.
I am using wordpress multisite,
But both selected languges are english for wordpress backend. But one i am using with RTL and the second one with LTR.

This is the point.
I tried to add language attribute it give me the same language for both sites.I am not using WPML plugin.

Hey There,

Do you have two separate WordPress installation? If yes, then you will need to set the languages for both installation to English and then in each of the child themes, you will need to edit the language attribute.

So in your main site, most probably in https://tarekrabaa.com/wp-content/themes/pro-child/views/header/, the child theme must have this base.php file.

<?php

// =============================================================================
// VIEWS/HEADER/BASE.PHP
// -----------------------------------------------------------------------------
// Declares the DOCTYPE for the site, includes the <head>, opens the <body>
// element as well as the .x-root <div> and .x-site <div>.
// =============================================================================

$x_root_atts = x_atts( apply_filters( 'x_root_atts', array( 'id' => 'x-root', 'class' => 'x-root' ) ) );
$x_site_atts = x_atts( apply_filters( 'x_site_atts', array( 'id' => 'x-site', 'class' => 'x-site site' ) ) );

?>

<!DOCTYPE html>

<html class="no-js" lang="ar" prefix="og: http://ogp.me/ns#">

<head>
  <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

  <div <?php echo $x_root_atts; ?>>

    <?php do_action( 'x_before_site_begin' ); ?>

    <div <?php echo $x_site_atts; ?>>

    <?php do_action( 'x_after_site_begin' ); ?>

And in your other separate install, https://tarekrabaa.com/en/wp-content/themes/pro-child/views/header/, must have this code:

<?php

// =============================================================================
// VIEWS/HEADER/BASE.PHP
// -----------------------------------------------------------------------------
// Declares the DOCTYPE for the site, includes the <head>, opens the <body>
// element as well as the .x-root <div> and .x-site <div>.
// =============================================================================

$x_root_atts = x_atts( apply_filters( 'x_root_atts', array( 'id' => 'x-root', 'class' => 'x-root' ) ) );
$x_site_atts = x_atts( apply_filters( 'x_site_atts', array( 'id' => 'x-site', 'class' => 'x-site site' ) ) );

?>

<!DOCTYPE html>

<html class="no-js" lang="en-US" prefix="og: http://ogp.me/ns#">

<head>
  <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

  <div <?php echo $x_root_atts; ?>>

    <?php do_action( 'x_before_site_begin' ); ?>

    <div <?php echo $x_site_atts; ?>>

    <?php do_action( 'x_after_site_begin' ); ?>

This will only if you have a separate installation. If you only have one, you will need a language selector plugin to be able to accomplish what you have in mind. Having to install a 3rd party plugin such as WPML should work and less hustle and any conflicts or issues.

Hope this helps.

Heillo,

I tried polylang. It is not compatible and it damaged my website.
Do you know about an efficient plungin?
The Plugin Multisite Language Switcher when i activate on my Arabic site it is keeping the Wordpress bakend in English but it is changing the output of pages and Post to RTL including the HTML codes. Also Wordpress front End turn into Arabic.

IN this case i need to Recustomize the postions of boxes and images.
With this plugin, even the PRO editor menus positions change to the right.

Is there any other solution?
I am using two sites with a main and a subdirectory for English.

I set as per the beginning of this thread the language to ar using base,php file i added.
However, my multi-site language is declared as Arabic in spite my subfolder https://tarekrabaa.com/en/ is english.

I don’t need a plugin to translate but just to declare in the Meta head the language of my Website without changing the language of the Wp-Admin. Because if i set my Wp-admin to arabic it will be a mixture of English and Arabic in the panel.

Hope you have a solution for this issue without switching my English version to another sub-domain because this requires a new PRO license.
thx

Hello Tarek!

I have a similar setup like yours, on the Arabic site I switch the “Site Language” in “WordPress Settings” to “العربية” this should be enough to switch the HTML language meta to ar, then you can install this plugin to switch only the WordPress Dashboard to English without messing with the front end nor the HTML language meta.

One note here, whenever you want to change the WordPress site language settings, you must disable this plugin first.

Let me know if you find this helpful!
Thanks.

It is helpful.
Thx

But the PRO editor becomes RTL and in mixed language.
However, I will evaluate the options and decides on what to do.

All those plugins options affect the design of my site which was already build. Even the Grid post is changing skin with arabic language. I will use a subdomain for my english website

Many Regards,

Please let us know the results of your evaluation.
We will also check out other options when using arabic and rtl in a site.

Hi,

I swtiched back to the english language and i used the option of adding the base.php file in https://tarekrabaa.com/wp-content/themes/pro-child/views/header/.

In this case all Wordpress is in English as well as the PRO editor, Another problem i had faced was in The GRID with was shifter to the left when selecting Arabic language in Wordpress Admin.
As a turnaround solution (maybe) i used a plugin Multisite Language Switcher on my english website which has now an alternative language to Arabic - English.

So the solution i am thinking to apply is to have another sub domain with separate installation for English Website.But there is the cost of an additional license of PRO!

Thx

If you have a solution to declare manually an alternative language for my arabic website then it will be solved.

/thx

Hi Tarek,

To show different language attribute and different alternative language tag on your sites in the multisite installtion you have, you can follow this method:

  • Replace the code you have in (/pro-child/framework/views/header/base.php) with this one:
<?php

// =============================================================================
// VIEWS/HEADER/BASE.PHP
// -----------------------------------------------------------------------------
// Declares the DOCTYPE for the site, includes the <head>, opens the <body>
// element as well as the .x-root <div> and .x-site <div>.
// =============================================================================

$x_root_atts = x_atts( apply_filters( 'x_root_atts', array( 'id' => 'x-root', 'class' => 'x-root' ) ) );
$x_site_atts = x_atts( apply_filters( 'x_site_atts', array( 'id' => 'x-site', 'class' => 'x-site site' ) ) );

$blog_id = get_current_blog_id();

if ( $blog_id == 1 ) {
    $lang_tag = 'lang="en-US"';
    $lang_alter = '<link rel="alternate" hreflang="ar" href="https://tarekrabaa.com/" />';  
}
if ( $blog_id == 2 ) {
    $lang_tag = 'lang="ar"';
    $lang_alter = '<link rel="alternate" hreflang="en" href="https://tarekrabaa.com/en" />';  
}
?>

<!DOCTYPE html>

<html class="no-js" <?php echo $lang_tag ?>>

<head>
  <?php wp_head(); ?>
  <?php echo $lang_alter; ?>
</head>

<body <?php body_class(); ?>>

  <div <?php echo $x_root_atts; ?>>

    <?php do_action( 'x_before_site_begin' ); ?>

    <div <?php echo $x_site_atts; ?>>

    <?php do_action( 'x_after_site_begin' ); ?>
  • This code will show different content based on the “$blog_id” which you can by going to (Network Admin > Sites) and hover on each site to reveal the ID in the browser as in this screenshot:

  • Make note of each site ID you have, because you will need to use that site ID in $blog_id == 1 for the English site, and $blog_id == 2 for the Arabic site in the code snippet I mentioned above.

That should do the trick,
Thanks.

1 Like

:thumbsup::thumbsup::thumbsup::thumbsup:
Excellent!!!

I am very happy to have this issue solved at last.

After 3 days of trying all available plugins on Wordpress, none of them give me the result i want.

Thank you very much indeed. You are very professional and smart.

Best Regards,
Tarek RABAA

On behalf of my colleague @Alaa, you are most welcome. :slight_smile:

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.