【狂人論壇】

 找回密碼
 註冊
搜索

[WordPress] 免外掛,不同作者的頁面顯示不同 AdSense 廣告

5496

主題

1萬

金錢

183

積分

不來恩

積分
183
brian 發表於 2016-7-10 21:38 | 顯示全部樓層 |閱讀模式



參考:https://www.techperiod.com/separ ... ing-wordpress-blog/


INTEGRATE ADSENSE REVENUE SHARING IN A MULTI-AUTHOR WORDPRESS BLOG

Assume that your blog have four authors. Create separate four adsense ad units with same format in your Adsense dashboard. If you use an ad unit of 468*60 size then create four different ad units with same size and give them the following name (for example) begin1, begin2, begin3, begin4.


Now, create four channels for four authors. Suppose the username the authors are Jit, Somnath, Sudip and Debjyoti. Give the channel name Jit, Somnath, Sudip and Debjyoti respectively and integrate each ad unit to each channel i.e. Jit -> begin1, Somnath -> begin2, Sudip -> begin3, Debjyoti -> begin4.
Note down, the ad slot ids. For example, ad lot id’s are as follows:

begin1 = 111111
begin2 = 222222
begin3 = 333333
begin4 = 444444

Now, open functions.php file of your wordpress blog and paste the following code:

function get_ad_codes($author) {
if($author == 'Jit')
   return '111111';
elseif ($author=='Somnath')
   return '222222';
elseif ($author=='Sudip')
   return '333333';
elseif ($author=='Debjyoti')
   return '444444';
else //default if no author found use for admin i.e. Jit here//
   return '111111'
}




Use the above function with in <?php ?> tag if necessary.


Now, open the single.php file of your WordPress blog and replace the existing code with the new one:


<ins class="adsbygoogle"
style="display:inline-block;width:468px;height:60px"
data-ad-client="ca-pub-xxxxxxxxxxxxxxx"
data-ad-slot="<?php echo get_ad_codes(get_the_author_login());?>"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>




You may use <?php get_the_author(); ?> function instead of <?php get_the_author_login(); ?> too.
Now, clear the cache of the website if you use any cache plugin and the website shows Adsense ads according to author’s post.


As, the blogger template does not support php (it supports javascript), so, you need to modify the above code before using this to Blogger blog. However, there are various Adsense revenue sharing plugins available in the market. But, I always prefer the manual method so that I can bypass unnecessary scripts to minimize page loading time.




參考:https://www.techperiod.com/separ ... ing-wordpress-blog/



您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|聯絡站長|重灌狂人|狂人論壇

GMT+8, 2024-3-19 16:00

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回復 返回頂部 返回列表