Ahmad Naser Turnkey Ecosystem Ahmad Naser
May 13, 2018

Multilingual Html, Css, Javascript to Your WordPress Site Using Wpml

Published in the Ahmad Naser ecosystem. Estimated reading time: 2 minutes.

Add Multilingual to your wordpress site using(wpml)

1-add the following line to:
functions.php

//Custom Script By Greenbackend.com 
include_once 'greenbackend/custom.php';

or download Functionality plugin to separate what you might normally place in a theme’s functions.php file, and put it in a plugin instead. It works the same way as a theme functions.php file, but is separate from the theme and so not affected by theme upgrades, or tied to the theme so you loose all of your functions if you choose to switch themes.
https://wordpress.org/plugins/functionality/

//Custom Script By Greenbackend.com 
include_once plugin_dir_path( __FILE__ ) .'../../themes/yourtheme/greenbackend/custom.php';

//*OR*//
//include_once ABSPATH .'wp-content/themes/yourtheme/greenbackend/custom.php';

2-create custom.php in greenbackend theme folder

<?php

//echo "greenbackend.com";

add_action('wp_enqueue_scripts','LoadCustomScript');

function LoadCustomScript(){
	
	if(ICL_LANGUAGE_CODE == 'en'){
	
		wp_enqueue_script("EnglishGBE","https://example.com/wp-content/themes/yourtheme/greenbackend/js/en.js");
			wp_enqueue_style("EnglishCSSGBE","https://example.com/wp-content/themes/yourtheme/greenbackend/css/en.css");	
}

if(ICL_LANGUAGE_CODE == 'ar'){
	
	wp_enqueue_script("ArabicGBE","https://example.com/wp-content/themes/yourtheme/greenbackend/js/ar.js");	
	
	
	wp_enqueue_style("ArabicCSSGBE","https://example.com/wp-content/themes/yourtheme/greenbackend/css/ar.css");	
}


if(ICL_LANGUAGE_CODE == 'he'){
	
		wp_enqueue_script("HebrewGBE","https://example.com/wp-content/themes/yourtheme/greenbackend/js/he.js");
			wp_enqueue_style("HebrewCSSGBE","https://example.com/wp-content/themes/yourtheme/greenbackend/css/he.css");	
}
	
}




?>

3- create two folders for js and css in greenbackend folder and add the css files and javascript files for each language
css folder
/css
ar.css
en.css
he.css
/js
ar.js
en.js
he.js

download sample from themes-greenbackend

Leave a Reply

Your email address will not be published. Required fields are marked *