Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.