Use plugin

There's a Google Adsense plugin for dokuwiki available located at this website; http://www.systemengineers.de/plugins/google-adsense It requires inserting codes to each and might not be very practical, and this is especially for a wiki system where everyone can actually create and edit pages.

Edit parser

The other method is to go to the core of Dokuwiki itself, and edit the parser. In this case, we'll make Google Adsense ad to appear after the H1 heading, just as how it normally appear in blogs.

The trick is to edit a function called header in <dokuwiki installation directory>/inc/parser/xhtml.php. Originally there's a line in the function as the following;

$this->doc .= "</a></h$level>".DOKU_LF;

What the line do is to add the right <Hn> tag to each heading levels as defined in Dokuwiki's syntax. What we need to do is to tweak it to add our Google Adsense code if the defined level is '1', just as the following;

        if ($level==1)
        {

                $this->doc .= "</a></h$level>";
                $this->doc .= '

<script type="text/javascript"><!--
google_ad_client = "pub-2726248188023431";
/* techrecipes - header */
google_ad_slot = "4924174629";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br />

<br />';

                $this->doc .= DOKU_LF;

        } else
        {
                $this->doc .= "</a></h$level>".DOKU_LF;
        }
Leave a comment:
Share!