Walker News

Using Trigger Text To Guide Adsense Placement Appears Randomly

Do you ever come across a newspaper or magazine that fix a column or position on every pages for advertisement? I guess no.

So, isn’t better to have different Adsense format or position appears in different posts?

For example, a rather short article displaying a smaller Adsense unit and an Adsense unit appears in the middle of a rather long article.

To achieve this purpose, I don’t think it’s practical to manually insert Adsense code into each post during compose time – in the case of any changes to Adsense code someday later, I’ve no choice but to edit each the posted article all over again!

So, the smarter way is by embedding a trigger text or marker in the post during compose time and have the PHP str_replace function to replace the trigger text/marker with Adsense code! You can define different Adsense trigger text for different Adsense format.
The trigger text or marker is actually a HTML comment text. For example,

<!– This Is HTML Comment Text –>
<!– more –>

How to implement Google Adsense trigger text in WordPress blog?
  1. Edit wp-includes/post-template.php,
  2. Look for the function the_post(),
  3. Add a variable to keep the Adsense code, immediately after that function header, e.g.
    $gads = 'Place Your Adsense code here';
  4. Right before the PHP code that call WordPress apply_filters function, write the PHP str_replace function to replace the trigger text (in this example, it’s <!–wgads–>) with Adsense code, i.e.
    $content = str_replace('<!--wgads-->', $gads, $content);
  5. Now, during post compose time, write the <!–wgads–> Adsense trigger text/marker anywhere of the article where the Adsense unit is expected to appear, e.g. in the second paragraph or in the middle of article.

As I’m not good in programming, so this is my dirty trick to achieve the purpose without using a customize WordPress plugin.

Also, this trick has no effects to posted article, unless you edit each of them by embedding such Adsense trigger text/marker! Otherwise, you might using a plugin (I remember I seen it before) that could decide after how many paragraphs then only the insert the Adsense code.

Custom Search

  1. Enable Full Text Feed In Wordpress 2.2 » Walker News 19-06-07@11:53

    […] full text feed publishing is still not working in WordPress 2.2 whenever I turn on MORE text link trigger text (the […]

  2. Welcome Adsense Crawler To Premium Content – Walker News 24-07-07@17:40

    […] usual, this new Adsense optimization feature will roll out in multiple phases. As long as you’ve transitioned Adsense Login to […]

  3. Embed Adsense Between Posts In New Blogger – Walker News 26-08-07@17:45

    […] few days ago, Google introduced New Blogger-Adsense integration feature that known as Inline Ads or Inline Adsense for New Blogger […]

  4. Why Enable Adsense Allowed Sites Feature – Walker News 23-09-07@17:34

    […] maintain reputation of Google Adsense, every publishers who implement Google adverts system have to strictly comply with the Adsense TOS. […]

  5. Adsense Paycheck Via Western Union Where EFT Not Available – Walker News 04-10-07@23:27

    […] Adsense earning electronically to publisher’s local bank account is certainly a better option than receiving […]

  6. Why Using Adsense Competitive Ad Filter – Walker News 15-11-07@01:04

    […] Displaying ads in a blog can be a win-win deal for both blogger and reader – quality ads help webmaster to pay off hosting bill while readers enjoy with information and services that are mostly relevant to the topic. That’s the purpose of Adsense contextual advertising! […]

2018  •  Privacy Policy