免插件在WordPress上添加广告的方法

免插件在WordPress上添加广告的方法

现在越来越多的人都做了自己的独立博客,并且博客流量也不少,那么也就不能白白浪费这些流量,故而我们可以在不影响用户体验上适当的加入一些广告,让流量转换为收入。下面我就向大家简单的介绍免插件WordPress上添加广告的方法。

WordPress博客添加广告一般有两种方法:一是安装广告插件,二是直接添加代码实现。本着插件越少越好的原则,我强烈推荐第二种方法,也就是给主题相关文件直接添加代码。

下面的一段代码可以帮助你实现不用插件也可以给博客文章中插入环绕效果的广告。

首先你要对wordpress的主题有点了解,你先在你当前使用的博客主题文件夹中找到single.php(文章页面)文件,用记事本打开文件,找到这段代码 <?php the_content(‘Read more…’); ?>在这段代码之前插入以下代码

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

同样道理,如果你想给文章的底部也加上广告,你可以继续往下找到这段代码 <?php comments_template(); ?> 将以下代码放到这段代码的前面

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

如果你想在博客的首页第一篇文章中和下面放置google adsense的广告,你可以在当前使用的主题文件夹下面找到index.php(首页页面)文件,用记事本打开,找到如下代码 <?php the_content(); ?>

在这段代码前面插入代码

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

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

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

这样做的优点是可以避免使用插件,但是缺点是如果你更换主题,你就要从新更改一次。

http://www.chenguangblog.com/archives/wordpress-add-advertising


如何在wordpress中添加优化Google Adsense广告代码

一、Wordpress日志内容页面添加环绕广告
进入你的Blog后台–>外观–>编辑 –> 打开 文章页面模板 (single.php)
或者直接下载 文章页面模板 (single.php) 文件,然后打开
找到这段代码 “php the_content” 在这段代码之前插入以下代码:

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

实现的关键是float:right

 

二、Wordpress日志内容页面底部添加广告
继续往下找到这段代码 php comments_template(); 将以下代码放到这段代码的前面

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

三、在Wordpress日志内容顶部加广告

打开single.php,找到php the_content();
在 php the_content(); 上面加上广告代码即可:

<div style=”padding-bottom:10px;padding-top:10px;”>
广告代码
</div>
<?php the_content(); ?>

四、Blog的首页第一篇文章下面放置google adsense的广告
可以在当前使用的主题文件夹下面找到index.php文件,打开
找到如下代码 php the_content();

 

在这段代码前面插入代码

 

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

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

<?php if ($wp_query->current_post == 0) : ?>
<div style=”padding-top:10px;text-align:center;”>
336*280Adsense代码
</div>
<?php endif; ?>

 

这些是一些常用的在wordpress中添加Google Adsense代码的技巧

http://linhun.com/1211.html


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值