Category Archives: Wordpress

WordPress – Add Google Analytics

Simply paste the code below and insert your Google Analytics where it says paste your .
You can paste the code once in your functions.php file and never have to worry about it again. We are adding an action to the wp_footer, so it will automatically insert adsense codes wherever on all pages you have the wp_footer string.

<?php add_action('wp_footer', 'add_googleanalytics');
function add_googleanalytics() { ?>
// Paste your Google Analytics code from Step 6 here
<?php } ?>

WordPress – Dynamic Copyright Date in Footer

Often you will come across sites with outdated copyright dates. Some sites show the current year as their copyright date. Both of these are annoying, and it shows that the site designer was lazy.

In order to give your users a little background info about your site, you should display the copyright date as such: © 2006 – 2010.

We can do this by simply pasting the following code:

function comicpress_copyright() {
  global $wpdb;
  $copyright_dates = $wpdb->get_results("
    SELECT
    YEAR(min(post_date_gmt)) AS firstdate,
    YEAR(max(post_date_gmt)) AS lastdate
    FROM
    $wpdb->posts
    WHERE
    post_status = 'publish'
    ");
  $output = '';
  if($copyright_dates) {
    $copyright = "&copy; " . $copyright_dates[0]->firstdate;
    if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
      $copyright .= '-' . $copyright_dates[0]->lastdate;
    }
  $output = $copyright;
  }
  return $output;
}

Once you add this function, then open your footer.php file and add the following code wherever you like to display the dynamic copyright date:

<?php echo comicpress_copyright(); ?>

This function looks for the date of your first post, and the date of your last post. It then echos the years wherever you call the function.

WordPress – Display Total Number of SQL Queries on Your Blog

Queries are evil. They slow down your site as you begin to accumulate more, which can negatively effect the user experience.
In fact, Google agrees too.

The first step to lowering queries is to know how many you actually have. Simply paste the following line of code somewhere on your site. I prefer going after the footer.php file.

<?php if (is_user_logged_in()) { ?>
    <?php echo get_num_queries(); ?> queries in <?php timer_stop(1); ?> seconds.
<?php } ?>

If you want this to be publicly shown, simply remove lines 1 and 3.