5ورڈپریس علامتایک پوسٹ کی آخری پیراگراف اوپر ایڈسینس کے اشتھارات

You may have noticed that we’ve tweaked how we dis­play our adsense ads. We wanted some small text-only ads near the bot­tom of each art­icle, which would be added auto­mat­ic­ally. This took a little bit of tinker­ing, but even­tu­ally we developed a solu­tion which works well and does­n’t seem to knock page pro­cessing times much. Simply add the fol­low­ing code to your theme’s functions.php (آپکے ایڈسینس آئی ڈیز کو تبدیل کرنے کی بھول نہیں ہے) 

Updated 12-Nov-2017 as the code was­n’t work­ing cor­rectly as pre­vi­ously dis­played. میں بھی شامل کیا ہے 2 oth­er func­tions that I use, one to insert adverts via short­code, and anoth­er to add an advert where the more is removed when a post is shown in full

/************************************************************************\
* کے اندراج کے لئے ایڈسینس مختصر کوڈ 2 مختصر کے ذریعے کہیں بھی چھوٹے اشتھارات *
\************************************************************************/
تقریب Google_Adsense( $ATTS, $مواد نل = ) {
   واپسی '<div کلاس ="ایک" سٹائل ="متن سیدھ: مرکز;"><div کی ID ="Google کے 1"></div کے><P سٹائل ="واضح: دونوں"></P></div کے>';
}
add_shortcode('google_adsense', 'Google_Adsense');




/******************************************\
* دکھائیں 2 زیادہ ٹیگ میں چھوٹے ایڈسینس کے اشتھارات *
\******************************************/
add_filter('مواد', 'adsense_added_at_more_tag');

// یہ فنکشن آپ کے ایڈسینس کے کوڈ کے ساتھ آپ زیادہ ٹیگ کی جگہ لے لے.
تقریب adsense_added_at_more_tag($متن) {
اگر( is_single() ) :
$ads_text = '<div کی ID ="گوگل" کلاس ="ایک" سٹائل ="متن سیدھ: مرکز;"><div کی ID ="Google کے 1"></div کے><P سٹائل ="واضح: دونوں"></P></div کے>';
$pos1 = strpos($متن, '<دورانیہ ID ="زیادہ- ');
//"
اگر($pos1 === جھوٹے) $متن = $ ads_text . $متن;
اور
{
$pos2 = strpos($متن, '</دورانیہ>', $pos1);
$text1 = substr($متن, 0, $pos1);
$text2 = substr($متن, $pos2 + 7);
$متن = $ text1 . $ads_text . $text2;
}
ختم کرو اگر;
واپسی $ متن;
}




/*******************************************************\
* آخری پیراگراف کے اوپر ایک بڑے ایڈسینس دکھائیں *
\*******************************************************/
add_filter('مواد', 'gads_added_above_last_para');

تقریب gads_added_above_last_para($ytext) {
اگر( is_single() ) :
$yads_text = '<div کلاس ="ایک" سٹائل ="متن سیدھ: مرکز;"><div کی ID ="Google کے 2"></div کے><P سٹائل ="واضح: دونوں"></P></div کے>';
اگر($ypos1 = strrpos($ytext, '</P>')){
$ytext1 = substr($ytext, 0, ($ypos1 + 4));
$ytext2 = substr($ytext, ($ypos1 + 4));
$ytext = $ ytext1 . $yads_text . $ytext2;
}
ختم کرو اگر;
واپسی $ ytext;
}

Leave a Reply

5 تبصرے

SJسارہ جونز

I don’t know but your code was not work­ing in my case. تو, I replaced it with oth­er code. If any­one else is facing the same prob­lem, then you can use the below code.

func­tion insert_ad_block( $متن ) {

اگر ( is_single() ) :

$ads_text = ‘My Ad Code Here’;
$split_by = “n”;
$insert_after = 2; //number of paragraphs

// make array of paragraphs
$para­graphs = explode( $split_by, $متن);

// if array ele­ments are less than $insert_after set the insert point at the end
$len = count( $para­graphs );
اگر ( $لین < $insert_after ) $insert_after = $len;

// insert $ads_text into the array at the spe­cified point
array_splice( $para­graphs, $insert_after, 0, $ads_text );

// loop through array and build string for output
ہر ایک کے لئے( $para­graphs as $para­graph ) {
$new_text .= $para­graph;
}

return $new_text;

ختم کرو اگر;

واپسی $ متن;

}
add_filter(‘the_content’, ‘insert_ad_block’);

جواب دیں
محترمہمیتھیو Snider

کے بعد اس کا کہنا ہے کہ ایسا کرنے کا ایک طریقہ ہے 2این ڈی بجائے گزشتہ ایک سے پہلے کے پیرا?

جواب دیں
جے ایسجان Scaife

بالکل. تم بس تھوڑا سا کوڈ موافقت کرنے کی ضرورت ہو گی. میں نے استعمال کر رہا ہوں strrpos جس کے آخری موجودگی کے پائے <p>
آپ کے دوسرے موجودگی کو تلاش کرنے کے لئے کرنا چاہتا تھا، تو <p> لائن کی جگہ لے لے 13 کوڈ سے اوپر کے ساتھ ...

اگر($pos1 = strpos($متن, '<P>', strpos($متن, '<P>') + 3)){
جواب دیں
جے ایسجان Scaife

اس بات کا یقین. کے ایک جوڑے شامل <گھنٹہ />کی - 1 at the start of the value of $ads_text and the oth­er at the end.
مثلا. replace

$ads_text = '<div کلاس ="ایک" سٹائل ="متن سیدھ: مرکز;"><script type="text/javascript"><!--
            google_ad_client = "ca-pub-0754629982287605";
            /* DMH-PostsMini */            google_ad_slot = "5138459326";
            google_ad_width = 468;
            google_ad_height = 15;
            //-->
            </سکرپٹ>
            <script type="text/javascript" ایسآرسی ="HTTPS://pagead2.googlesyndication.com/pagead/show_ads.js">
            </سکرپٹ></div کے>';

کے ساتھ

$ads_text = '<گھنٹہ /><div کلاس ="ایک" سٹائل ="متن سیدھ: مرکز;"><script type="text/javascript"><!--
            google_ad_client = "ca-pub-0754629982287605";
            /* DMH-PostsMini */            google_ad_slot = "5138459326";
            google_ad_width = 468;
            google_ad_height = 15;
            //-->
            </سکرپٹ>
            <script type="text/javascript" ایسآرسی ="HTTPS://pagead2.googlesyndication.com/pagead/show_ads.js">
            </سکرپٹ></div کے><گھنٹہ />';
جواب دیں