Skip to content

Instantly share code, notes, and snippets.

@noeltock
Last active December 16, 2015 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noeltock/5371335 to your computer and use it in GitHub Desktop.
Save noeltock/5371335 to your computer and use it in GitHub Desktop.
Universal Analytics / WordPress
<?php
function nt_ga_word_count() {
global $post;
$id = $post->ID;
$count = str_word_count( get_post_field( 'post_content', $id ) );
return ceil( $count / 100 ) * 100;
}
function nt_ga_post_age() {
global $post;
$id = $post->ID;
$now = date('Y-m-d');
$then = get_the_time('Y-m-d', $id);
return (int)abs((strtotime($now) - strtotime($then))/(60*60*24*30));
}
function nt_ga_comment_count() {
global $post;
$id = $post->ID;
$comments = wp_count_comments( $id );
return $comments->approved;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment