Cara Pasang Adsense Pada Posting WordPress Otomatis

Untuk memasang iklan google adsense pada setiap artikel wordpress dapat dilakukan dengan mengedit template post pada script php WordPress.
Script php yang harus diubah adalah /wp-includes/post-template.php

Buka script tersebut dengan menggunakan FTP, kemudian edit.
Cari function the_content, kemudian ubah dengan script berikut ini:

function the_content( $more_link_text = null, $strip_teaser = false) {
	$content = get_the_content( $more_link_text, $strip_teaser );
	$content = apply_filters( 'the_content', $content );
	$tmpcontent = $content;
	while ((stristr($tmpcontent,'<br />') || stristr($tmpcontent,'</p>'))&& $titik < strlen($content)/4) {
	$tmpcontent = substr($tmpcontent,$ttk);
	$ttk = strpos($tmpcontent, '<br />');
	if ($ttk) {
		$ttk+=6;
	} else {
		$ttk = strpos($tmpcontent, '</p>');
		if ($ttk) $ttk+=4;
	}
	$titik += $ttk;
	}
	$cc = substr($content,0,$titik);
	$dd = substr($content,$titik);
	$content = $cc . '<span class="alignright"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><ins class="adsbygoogle" style="display:inline-block;width:200px;height:200px" data-ad-client="ca-pub-3709515531962980" data-ad-slot="9236036214"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></span>' . $dd;
	$content = str_replace( ']]>', ']]&gt;', $content );
	echo $content;
}

Perlu diperhatikan pada penulisan script yang mau ditambahkan, harus dalam satu baris. Karena kalau tidak dalam satu baris WordPress secara otomatis akan menambahkan <br/> sehingga dapat merusak script yang ditambahkan khususnya JavaScript.
Ganti data-ad-client dan data-ad-slot sesuai dengan data adsense anda.

Facebook Comments

Leave a Reply

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