How to add the uberVU reaction counter to posts using WordPress – Thesis

door jules op 14 January 2010 22:55

Adding the uberVU reaction counter to a webpage is simple. Nevertheless, I ran into some issues, which I overcame and would like to share:

I use WordPress with the Thesis theme and made a routine in custom_functions.php to do the trick. The code (below) does the following:

  • Strip extra URL parameters
  • Only display on single posts (not on pages)
  • Insert the badge after the pot headline using the appropriate Thesis hook

Here’s the code I used to insert the counter next to the post:

<?php
function jbl_ubervu() {  
  if (is_single()) { ?>
    <div class="ubervu_button" style="float: right; margin-left: 5px; margin-right:5px;">
    <script type="text/javascript">
      var ubervu_url = "<?php echo get_permalink(); ?>";
      var ubervu_style = "compact";
    </script>
    <script type="text/javascript" src="http://badge.ubervu.com/badge.1.0.js"></script>
    </div>
  <?php } 
}
add_action('thesis_hook_after_headline', 'jbl_ubervu');
?>

The reason for using the permalink is to strip extra url variables, like Google Analtytics campaign parameters. The uberVU script can never know which parameters to ignore, so you might end up with different counters.

Hack away, cut-and-paste, and leave a comment if it works for you or not.

Laat een comment achter