最佳 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 网站管理员插件,它有标题部分供您将内容放入主题的标题中。