WordPress中如何非插件添加谷歌广告联盟广告Google Adsense

WordPress中如何非插件添加谷歌广告联盟广告Google Adsense,在WordPress官方网站或GOOGLE上都能够找到Wordpress Adsense的插件,然而太麻烦。现在只需要小小的改动便能够实现在wordpress博客上插入谷歌广告联盟广告了。功能:让文章内容环绕Google Adsense的周围,直接在模板代码中添加。

1.WordPress文章内容页面添加环绕谷歌或者百度广告

进入wordpress博客后台–>外观–>编辑 –> 打开 文章页面模板 (single.php)

或者直接下载 文章页面模板 (single.php)  文件,然后打开

找到这段代码 <?php the_content 在这段代码之前插入以下代码:

1 <div style="float:left;width:300px;height:250px;">你的广告代码</div>

关键是float:left 其中:float:left是靠左,float:right是靠右,width:300px;height:250px;这个是广告位置的宽和高,可以根据广告大小进行调整.

2.WordPress日志文章内容页面底部添加广告 继续往下找到这段代码 &lt;?php comments_template(); ?&gt; 将以下代码放到这段代码的前面:

1 <div style=”float:right; padding-bottom:10px;padding-top:10px;”>广告代码</div>

3.在WordPress日志内容顶部加广告 打开single.php,找到<?php the_content(); ?> 在 <?php the_content(); ?> 前面加上广告代码即可:

1 <div style=”padding-bottom:10px;padding-top:10px;”>广告代码</div>

4.wordpress博客的首页第一篇文章下面放置google adsense的广告 可以在当前使用的主题文件夹下面找到index.php文件,打开 找到如下代码 <?php the_content(); ?> 在这段代码前面插入代码:

1 <?php if ($wp_query->current_post == 0) : ?>
2 <div style=”float:right; padding-bottom:10px;padding-top:10px;”>广告代码</div>
3 <?php endif; ?>

在<?php the_content(); ?>这段代码的后面插入

1 <?php if ($wp_query->current_post == 0) : ?>
2 <div style=”padding-top:10px;text-align:center;”>广告代码</div><?php endif; ?>

5.在WordPress博客侧栏放置广告:

这个最简单也最常见,打开使用中的主题文件夹找到“sidebar.php”,加入下面的代码

把widget改成你主题侧栏使用的样式,或自定义一个:

1 <div>
2  <h3>Ad – Google</h3>
3 广告代码
4 </script>
5  </div>

本文链接地址: WordPress中如何非插件添加谷歌广告联盟广告Google Adsense