Hi Justin
A couple of years ago you helped me to get GATCW working in conjunction with GAD using the following two pieces of code:
1) Installed in the single.php file
<?php echo do_shortcode('[google_top_content pageviews="5" titleremove= "Focusing on Wildlife" contentfilter="post" catfilter="3173" number="10" showhome="no" time="2628000"]'); ?>
2) Installed in the functions.php file:
add_filter( 'gtc_pages_filter', 'gtc_add_viewcount_title' );
function gtc_add_viewcount_title( $pages ) {
if ( !$pages )
return false;
// loop through the pages
foreach ( $pages as $key => $page ) {
// and add the page count to the title value
$pages[$key]['children']['value'] = $pages[$key]['children']['value'] . ' ['. $pages[$key]['children']['children']['ga:pageviews'] .' Views]';
}
return $pages;
}
Now after replacing GAD by “Google Analytics by Yoast”, the 10 top posts are still being listed correctly but the page count is not showing after each post title.
Do I need to change something in either of the 2 pieces of code to get the page counts to show up?
Please advise
Hey, yah, those parameters have changed a bit w/ the new plugin integration. We actually have a handy title filter now as well. To accomplish what you’re asking, you would use this (functions.php) snippet instead:
function gtc_page_title_add_viewcount_total( $title, $analytics ) {
if ( isset( $analytics['value'] ) ) {
// Add the page view count to the title value
$title .= ' ['. absint( $analytics['value'] ) .' Views]';
}
return $title;
}
add_filter( 'gtc_page_title', 'gtc_page_title_add_viewcount_total', 10, 2 );
Hi Justin
The top 10 posts with view count works perfectly now after updating the functions.php file and can be seen in action on the following typical post (scroll down to the bottom of the page to see the post rankings):
http://focusingonwildlife.com/news/promoting-wildlife-conservation/
I have added an addendum to the positive review. Thanks once again for responding so quickly with the coding solution to this issue.