在WordPress文章内随机段落插入Google AdSense广告

对于世界各地的网站所有者来说,Google AdSense是最流行的赚钱方式之一,你可以轻松将Google AdSense广告添加到自己的网站中,并立即开始赚钱。Google AdSense是谷歌运营的一个广告网络,使博客作者和网站所有者有机会通过在网站上显示文字、图片、视频等互动广告来赚取收入,这些广告以网站内容和精准受众为目标。

使用Google AdSense赚钱非常简单,你不必与广告商打交道,也不必担心赖账。Google管理并维护与广告商的关系,他们收取广告款和管理费,然后将其余的钱通过国际电汇、西联汇款等方式发给你。Google AdSense提供CPC广告,这意味着每当用户点击网站上的广告时,你都能赚钱,每次点击费用受很多因素影响,但主要取决于广告商所设置的最高价格。

首先,您必须将Google Adsense添加到您的WordPress网站并验证您的网站所有权。在申请审核通过后在你的网站上挂上广告,广告代码会根据你的网站内容和访客网络记录在你的网站上实现广告展示,你将获得这些广告获得的点击次数的报酬以及广告的展示报酬。

如果你还不知道如何创建Google Adsense帐户,可以参考我之前写的这篇文章:https://www.11zhang.com/308.html

如果你不想使用插件,纯代码实现在WordPress文章内随机段落插入Google AdSense广告,那么,你可以将下面的代码添加到当前主题的 functions.php 文件即可。注意按照下面的注释修改广告代码!

//文章内随机段落插入Google AdSense广告(由十一张站长整理www.11zhang.com)

add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads($content){
    $pattern = "/<p>.*?<\/p>/";
    $paragraph_count = preg_match_all($pattern,$content); //计算文章的段落数量
    if($paragraph_count >= 8 && is_single()){//如果文章的段落数量少于8段,则不会插入文章段落广告
    $paragraph_count -=2;
    $insert_paragraph=rand(3,$paragraph_count);
    $ad_code = '<div>你的广告代码</div>'; 
    return prefix_insert_after_paragraph( $ad_code, $insert_paragraph, $content );
    }
    return $content;
}
     
// 插入广告所需的功能代码
function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
         $closing_p = '</p>';
    $paragraphs = explode( $closing_p, $content );
    foreach ($paragraphs as $index => $paragraph) {
        if ( trim( $paragraph ) ) {
            $paragraphs[$index] .= $closing_p;
        }
        if ( $paragraph_id == $index + 1 ) {
            $paragraphs[$index] .= $insertion;
        }
    }
    return implode( '', $paragraphs );
}

Google AdSense每个月都会计算你的上月收入,并将其显示在付款页面上。如果你的收入符合要求的起付额度,他们将会在当月21日进行处理。Google提供多种付款方式,包括电子转帐、国际电汇、西联汇款、支票等等。

✅来源:十一张博客
© 版权声明
THE END
如果觉得这篇文章对您有帮助,不妨考虑请我喝杯奶茶😄
点赞6赞赏 分享
评论 抢沙发
头像
评论人工审核通过显示,请勿重复提交!
提交
头像

昵称

取消
昵称表情代码

    暂无评论内容