Welcome to Geeklog, Anonymous Saturday, June 22 2024 @ 05:11 am EDT

Geeklog Forums

Adding a +1 button

Status: offline


Site Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
I wanted to add a Google +1 button to one of my sites. The instructions are easy enough but I thought a little writeup can't hurt.

The theme I'm using is loosely based on the Professional theme, so it has the story icons (email, printer, edit option) next to the story title. That seems like a good place to put the +1 icon as well. There's a small version of the icon which fits there just fine.

Step 1: In storytext.thtml, featuredstorytext.thtml, and archivestorytext.thtml, add a new template variable "plus_one":
Text Formatted Code
<div class="story">
    <span class="story-icons">

Step 2: To populate that variable, we need a small snippet of code in lib-custom.php. Find the function CUSTOM_templateSetVars, make sure it's not commented out(!), then add this piece of code:
Text Formatted Code

function CUSTOM_templateSetVars($templatename, &$template)
    case 'storytext':
    case 'featuredstorytext':
    case 'archivestorytext':
        if (strpos($_SERVER['PHP_SELF'], 'article.php') !== false) {
            $template->set_var('plus_one', '<g:plusone size="small"></g:plusone>');

This makes sure that the +1 button only appears on the article page but not on the index pages.

Step 3: If you're using Geeklog 1.8.0, add this new function to your lib-custom.php (see below for instructions for older Geeklog versions):
Text Formatted Code

function CUSTOM_getfootercode()
    $retval = '';

    if (strpos($_SERVER['PHP_SELF'], 'article.php') !== false) {
        $retval = '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>';

    return $retval;

On Geeklog 1.8.0, you're already done now. Check your article pages for your shiny new +1 button.

Step 4: (Geeklog versions prior to 1.8.0 only) We need to introduce another template variable. This time for the footer template. In lib-custom.php again, add this piece of code to the CUSTOM_templateSetVars that you just edited in Step 2:
Text Formatted Code

    case 'footer':
        if (strpos($_SERVER['PHP_SELF'], 'article.php') !== false) {
            $jsplus = '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>';
            $template->set_var('plus_js', $jsplus);

Step 5: (Geeklog versions prior to 1.8.0 only) Now we need to add the new "plus_js" variable to the theme's footer.thtml file. Put it right before the closing body tag (and leave the rest of the file as it is):
Text Formatted Code


And now the +1 button should appear in your articles.

Happy +1ing.

bye, Dirk

Status: offline


Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
:shakehands: Thanks for this tutorial.

I'm available to customise your themes or plugins for your Geeklog CMS

All times are EDT. The time is now 05:11 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content