Insert Google Adsense in Between Gallery Rows

Google Adsense in between Gallery rows
Google Adsense in between Gallery rows

I use Gallery for my gallery page, with Google Adsense ads. By Integrate Gallery into WordPress, I am able to add Adsense code at page header and/or footer.

But, since my album is displayed in 3 rows, I think putting Adsense ads in between Gallery rows will better increase the appearance and click rate(hopefully :wink:).

Problem
I search through Internet but failed to find helpful resources. The “html_wrap” files only support for Header, Footer, and Frame. Doesn’t has html wrap for Gallery Rows.

At the end, I solved it by myself with dirty trick. Read on for details.

Solution
Since html_wrap does not help this time. I modified the “view_album.php” file to get my ads display in between rows. “view_album.php” is the PHP file to display photo albums in Gallery.

Warning! Editing “view_album.php” is NOT recommended. Make sure you have backup the file first before modify it. Backup!

Insert Google Adsense Code In Between Gallery Rows

  1. Backupview_album.php” file!
  2. Open “view_album.php" for editing.
  3. Search for the following lines of code:
    [php]if ($printTableRow) {
    echo(”);
    }
    $rowCount++;
    $rowStart = $visibleItemIndex;[/php]
  4. Insert your Google Adsense code AFTER:
    [php]if ($printTableRow) {
    echo(”);[/php]
    and, BEFORE :
    [php]}
    $rowCount++;
    $rowStart = $visibleItemIndex;[/php]
  5. If you are doing it right, it will looks something like this:
    [php]if ($printTableRow) {
    echo(”);
    // START – Insert adsense in between Gallery row
    ?>

Share this:

Leave a Comment