最佳 WordPress Adsense 插件 – 如何在沒有插件的情況下在帖子中間添加 Adsense 廣告代碼
已發表: 2018-05-04 Adsense 是目前在全球範圍內廣泛使用的廣告網絡。 90%
的網站服務於 Adsense 廣告,包括我們在內。
您有以下 Adsense 問題嗎? 那麼你來對地方了:
- 為 AdSense 插件手動插入展示位置代碼
- AdSense for WordPress 無插件
- 在 WordPress 中添加 Adsense 廣告的簡單方法
- 使用 Adsense 在線賺錢的最佳方式
Option-1:
使用插件:讓我們首先開始使用 WordPress 插件:
Google 的 AdSense 計劃可讓您在您的網站上為其他人的廣告出售廣告空間,而不僅僅是 Google 選擇的任何廣告,還包括與您網站的內容頁面相關的廣告,就像任何其他社交媒體網站一樣。 該服務是免費的,每次有人點擊廣告時,您都會賺錢。 Google 的 AdSense 可能是從包含精彩內容的網站中獲得收入的fastest and easiest
的方法。
大多數網站管理員依靠 Google Adsense 從他們的博客/網站中獲得收入。 在 WordPress 博客中添加 Google Adsense 有點困難。 為了幫助新的網站管理員,我收集了兩個最好的 Adsense WordPress 插件,它們可以在 WP Registry 上找到。
1) 谷歌 Adsense 廣告管理器
Link:
https://wordpress.org/plugins/simplest-adsense-ads-manager/
最簡單的 Google Adsense 配置 WordPress 插件之一。 通過正確配置 Adsense 獲得最大的 Google Adsense 收入。
為什麼這麼簡單?
- 到目前為止,您可能已經使用了這麼多 Adsense 插件,但沒有一個能滿足您的自定義需求。
- 非常簡單的界面
- 在文本區域中添加 HTML 的選項,您可以在其中指定 adsense 代碼
- 指定對齊選項的選項:右、左、居中
- 指定條件的選項。 顯示在主頁/頁面/帖子或全部
- 沒有性能影響——沒有額外的代碼
- 在特定帖子/頁面上禁用 AdSense 代碼的選項
2) AdSense 的簡易插件
Link:
http://wordpress.org/plugins/easy-adsense-lite/
Easy AdSense 提供了一種使用 Google AdSense 從您的博客中創收的方法。 憑藉其全套功能,Easy AdSense 可能是第一個為您提供與 AdSense 相關的所有內容的完整解決方案的插件。 Easy AdSense 執行 Google AdSense 政策,即每頁不超過三個 AdSense 塊。
Easy Adsense 提供側邊欄小部件:
- 對於具有自定義標題的 AdSense 內容廣告。
- 使用可自定義的文本或圖像標題進行搜索。
- 將鏈接單元或 AdSense 塊放在頁眉或頁腳中。
- 禁止在所有頁面(而不是帖子)或首頁/主頁上顯示廣告。
- 在廣告塊上添加可自定義的鼠標懸停邊框裝飾。
Option-2:
不使用插件將 Adsense 代碼添加到您的主題中:
早在 2009 年很長時間以來,我一直在使用 Adsense 通過我的網站獲利。因為您可能需要在第 1 段之後添加728x90 banner ads
,而您可以在第 2 段之後添加336x300 large rectangle ads
。
為了實現這一點——您可能不需要使用任何插件,而是使用一些 WordPress 鉤子和技巧手動添加它。 那裡有許多流行的 WordPress 插件可用,但不應該為我們博客上的每一件小事都使用插件。
讓我們開始吧:
第1步
打開你的主題的functions.php
文件並將下面的代碼放入其中。 這裡我們使用了兩個變量single_post_ads
和home_page_ads
。 只需替換<div>
和</div>
之間的數據。 在這裡,我使用樣式 CSS 參數,您可以根據需要進行修改。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
//Insert Adsense code in the middle of Single Post content add_filter ( 'the_content' , 'crunchify_ads' ) ; function crunchify_ads ( $ content ) { // Ad code which we are using on Single post $ single_post_ads = '<div align="center"> <ins class="adsbygoogle" data-ad-client="ca-pub-xxxxxxxxxxxxxxxx" data-ad-slot="7211141298"></ins> <script> ( adsbygoogle = window . adsbygoogle | | [ ] ) . push ( { } ) ; </script> </div>' ; // Ad code which we are using on Home/Inde page $ home_page_ads = '<div align="center"> <ins class="adsbygoogle" data-ad-client="ca-pub-xxxxxxxxxxxxxxxx" data-ad-slot="1831796969"></ins> <script> ( adsbygoogle = window . adsbygoogle | | [ ] ) . push ( { } ) ; </script> </div>' ; if ( is_single ( ) && ! is_admin()) { return crunchify_insert_ads( $single_post_ads, 2, $content ); } if ( is_home ( ) && ! is_admin()) { return crunchify_insert_ads( $home_page_ads, 1, $content ); } return $ content ; } |

第2步
將以下代碼也添加到functions.php
文件中。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// This function identifies after which paragraph we need to insert ads function crunchify_insert_ads ( $ ads , $ after_which_paragraph , $ content ) { $ identify_paragraph = '</p>' ; $ crunchifyData = explode ( $ identify_paragraph , $ content ) ; foreach ( $ crunchifyData as $ index = > $ paragraph ) { if ( trim ( $ paragraph ) ) { $ crunchifyData [ $ index ] . = $ identify_paragraph ; } if ( $ after_which_paragraph == $ index + 1 ) { $ crunchifyData [ $ index ] . = $ ads ; } } return implode ( '' , $ crunchifyData ) ; } |
上面的代碼將識別它是which paragraph
以及在哪裡添加代碼。 </p>
表示段落的結尾。 如果您發現任何問題,請告訴我。
額外提示:
正如你在上面的代碼中看到的——我沒有添加adsbygoogle.js
腳本並將其放入 functions.php 中:
1 |
<script async src = "http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" > </script> |
如果您有 3 個 Adsense 代碼,則將相同的腳本添加 3 次是no point
的。 只需將它添加到您的主題標題一次,一切都很好。 我使用 All in One 網站管理員插件,它有標題部分供您將內容放入主題的標題中。