Skip to content

Instantly share code, notes, and snippets.

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 jtsternberg/449b7ea79fd5ad460143 to your computer and use it in GitHub Desktop.
Save jtsternberg/449b7ea79fd5ad460143 to your computer and use it in GitHub Desktop.
For Google Analytics Top Content Widget: Add the analytics count next the item title
<?php
/**
* Add the analytics count next to the item title
*
* @param string $title The page/post/etc title
* @param array $analytics Array of analytics data
*
* @return string Modified item title
*/
function gtc_page_title_add_viewcount_total( $title, $analytics ) {
if ( isset( $analytics['value'] ) ) {
$count = absint( $analytics['value'] );
// Add the page view count to the title value
$title .= " [$count Views]";
}
return $title;
}
add_filter( 'gtc_page_title', 'gtc_page_title_add_viewcount_total', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment