Dua project wordpress terakhir yang saya kerjakan butuh fitur support multilingual, biasanya untuk support multilingual di wordpress saya menggunakan plugin WPML, cuma karena WPML adalah plugin berbayar, akhirnya harus cari cari yang gratis dan mirip mirip dengan WPML biar adaptasi penggunaannya juga cepet. Maka ketemulah Polylang, wordpress plugin multilingual gratisan dan mendekati fitur yang diberikan WPML, untuk versi gratisan Polylang ini sangat oke. Tapi masalah muncul ketika harus memadukan antara plugin breadcrumb NavXT, plugin ini yang biasa pakai dan belum ingin beralih, karena  menurut saya cukup keren dan mudah settingnya.

Ketika memakai Polylang, language breadcrumb trail nya tidak ikut berubah sesuai current language. Yang tertampil adalah default language nya meskipun bahasanya sudah diubah ke bahasa yang lain. Masalah yang belum pernah muncul ketika saya memadukan WPML dengan Breadrumb NavXT. Setelah cari cari informasi, ternyata Breadcrumb NavXT belum men-support Polylang. Mau ga mau akhirnya harus ubah code di plugin Breadcrumb NavXT, bukan solusi yang bagus sih menurut saya, karena ketika ada update plugin, maka baris code yang kita tambahkan akan ter-replace, jadi kita pun harus nambah code lagi setiap habis update plugin, tapi ya gimana lagi plugin Breadcrumb NavXT belum menyediakan Hook untuk nambah code di function theme kita sendiri, supaya bisa support polylang.

So, solusi yang saya gunakan adalam menambah baris code di function find_type yang ada di file class.bcn_breadcrumb_trail.php, berikut adalah hasil modikasi code plugin Breadcrumb NavXT supaya support dengan Polylang.

protected function find_type($type, &$type_str, &$root_id)
	{
		global $wp_taxonomies;
		//We need to do special things for custom post types
		if(is_singular() && !$this->is_builtin($type->post_type))
		{
			//We need the type for later, so save it
			$type_str = $type->post_type;
			//This will assign a ID for root page of a custom post
			if(is_numeric($this->opt['apost_' . $type_str . '_root']))
			{
				$root_id = $this->opt['apost_' . $type_str . '_root'];

				// add this code for support polylang
				$root_id = pll_get_post($root_id, pll_current_language());
			}
		}
		//For CPT archives
		else if(is_post_type_archive() && !isset($type->taxonomy))
		{
			//We need the type for later, so save it
			$type_str = $type->name;
			//This will assign a ID for root page of a custom post's taxonomy archive
			if(is_numeric($this->opt['apost_' . $type_str . '_root']))
			{
				$root_id = $this->opt['apost_' . $type_str . '_root'];
			
				// add this code for support polylang
				$root_id = pll_get_post($root_id, pll_current_language());
			}
		}
		//We need to do special things for custom post type archives, but not author or date archives
		else if(is_archive() && !is_author() && !is_date() && !$this->is_builtin($this->get_type_string_query_var($wp_taxonomies[$type->taxonomy]->object_type[0])))
		{
			//We need the type for later, so save it
			$type_str = $this->get_type_string_query_var($wp_taxonomies[$type->taxonomy]->object_type[0]);
			//This will assign a ID for root page of a custom post's taxonomy archive
			if(is_numeric($this->opt['apost_' . $type_str . '_root']))
			{
				$root_id = $this->opt['apost_' . $type_str . '_root'];
			
				// add this code for support polylang
				$root_id = pll_get_post($root_id, pll_current_language());
			}
		}
		else
		{
			$type_str = 'post';
		}
	}

 

  1. Mansi
    Dec 13, 2016

    This is a nice post how to make Breadcrumb NavXt Multilingual.
    can you also explain how to make the Home Link Multilingual with polylang

    Reply