Canza jagorar WordPress a cikin Header

Jagorar Rubutun WordPress

The Maballin juyawa an gina shi don WordPress babbar hanya ce ta tsarawa da sarrafa canje-canje. Ina amfani da shi a wannan rukunin yanar gizon kuma na tsara ƙungiyoyi na juyarwa don abubuwan da aka sabunta, hanyoyin haɗin gwiwa, saukarwa, da sauransu.

Koyaya, Na shiga cikin matsala ta musamman inda ina da wakili na baya wanda aka saita don abokin ciniki inda WordPress ke gudana a hanya… amma ba asalin shafin ba. Shafin farko yana gudana akan IIS a Azure. IIS na iya gudanar da turawa kamar yadda kowane sabar yanar gizo zai iya, amma matsalar ita ce, wannan abokin cinikin zai buƙaci saka canjin canjin cikin aikin ci gaban su - kuma suna kan aiki tuni.

Abin da ake magana a kai shine, yanayin tura turaren juzu'i .htaccess ba abu ne mai yuwuwa ba… dole ne a zahiri mu rubuta wuraren da aka tura a cikin PHP. A matsayin mafita, muna bin buƙatun zuwa WordPress don gano idan akwai canje-canje a kan tsoffin hanyoyi.

A cikin header.php fayil ɗin taken ɗanmu, muna da aiki:

function my_redirect ($oldlink, $newlink, $redirecttype = 301) {
	$olduri = $_SERVER['REQUEST_URI'];
	if(strpos($olduri, $oldlink) !== false) {
		$newuri = str_replace($oldlink, $newlink, $olduri);
		wp_redirect( $newuri, $redirecttype );
		exit;
	}
}

Ba mu damu da sanya aikin a cikin ayyuka.php kawai ba saboda kawai zai shafi fayil ɗin taken ne kawai. Bayan haka, a cikin fayil ɗin header.php, kawai muna da jerin duk abubuwan da aka turawa:

my_redirect('lesson_plans', 'lesson-plan');
my_redirect('resources/lesson-plans/26351', 'lesson-plan/tints-and-shades');
my_redirect('about/about', 'about/company/');

Tare da wannan aikin, zaka iya tantance wane nau'in turawa kake so ka saita buƙatun taken, yanzu mun ƙaddamar da shi zuwa turawa 301 don injunan bincike su girmama shi.

Me kuke tunani?

Wannan shafin yana amfani da Akismet don rage spam. Koyi yadda aka sarrafa bayanan bayaninka.