DIY मीडिया होम लोगो

अपनी खुद की होम थिएटर और हाय-Fi सेटअप डिजाइन और बनाने के लिए परम साइट.

5Wordpress लोगोएक पोस्ट का अंतिम पैरा ऊपर ऐडसेंस विज्ञापन

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 (don’t for­get to change your adsense IDs

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 class ="ए" शैली ="पाठ संरेखित: केंद्र;"><div id ="गूगल-1"></div><p style ="स्पष्ट: दोनों"></पी></div>';
}
add_shortcode('गूगल ऐडसेंस', 'गूगल ऐडसेंस');




/******************************************\
* दिखाना 2 अधिक टैग पर छोटे adsense विज्ञापन *
\******************************************/
add_filter('सामग्री', 'Adsense_added_at_more_tag');

// यह समारोह अपने ऐडसेंस कोड के साथ अपने अधिक टैग को बदलने.
समारोह adsense_added_at_more_tag($टेक्स्ट) {
अगर( अकेला है() ) :
$ads_text = '<div id ="गूगल" वर्ग ="ए" शैली ="पाठ संरेखित: केंद्र;"><div id ="गूगल-1"></div><p style ="स्पष्ट: दोनों"></पी></div>';
$pos1 = strpos($टेक्स्ट, '<span id ="अधिक-');
//"
अगर($pos1 === FALSE) $पाठ = $ ads_text . $टेक्स्ट;
अन्य
{
$pos2 = strpos($टेक्स्ट, '</विस्तार>', $pos1);
$टेक्स्ट 1 = substr($टेक्स्ट, 0, $pos1);
$टेक्स्ट 2 = substr($टेक्स्ट, $pos2 + 7);
$पाठ = $ टेक्स्ट 1 . $ads_text . $टेक्स्ट 2;
}
अगर अंत;
वापसी $ पाठ;
}




/*******************************************************\
* अंतिम अनुच्छेद ऊपर एक बड़ी ऐडसेंस विज्ञापन दिखाएं *
\*******************************************************/
add_filter('सामग्री', 'Gads_added_above_last_para');

समारोह gads_added_above_last_para($ytext) {
अगर( अकेला है() ) :
$yads_text = '<div class ="ए" शैली ="पाठ संरेखित: केंद्र;"><div id ="गूगल-2"></div><p style ="स्पष्ट: दोनों"></पी></div>';
अगर($ypos1 = strrpos($ytext, '</पी>')){
$ytext1 = substr($ytext, 0, ($ypos1 + 4));
$ytext2 = substr($ytext, ($ypos1 + 4));
$ytext = $ ytext1 . $yads_text . $ytext2;
}
अगर अंत;
वापसी $ ytext;
}

उत्तर छोड़ दें

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( $टेक्स्ट ) {

अगर ( अकेला है() ) :

$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’);

जवाब दें
जेएसजॉन Scaife

Abso­lutely. You would just need to tweak the code slightly. I’m using strrpos which finds the last occur­rence of <p>
If you wanted to find the second occur­rence of <p> replace line 13 from the code above with…

अगर($pos1 = strpos($टेक्स्ट, '<पी>', स्ट्रोपोस($टेक्स्ट, '<पी>') + 3)){
जवाब दें
जेएसजॉन Scaife

ज़रूर. Add a couple of <hr />‘s — 1 at the start of the value of $ads_text and the oth­er at the end.
उदा.. replace

$ads_text = '<div class ="ए" शैली ="पाठ संरेखित: केंद्र;"><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" src ="HTTPS के://pagead2.googlesyndication.com/pagead/show_ads.js">
            </लिपि></div>';

साथ

$ads_text = '<hr /><div class ="ए" शैली ="पाठ संरेखित: केंद्र;"><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" src ="HTTPS के://pagead2.googlesyndication.com/pagead/show_ads.js">
            </लिपि></div><hr />';
जवाब दें