Skip to content

Instantly share code, notes, and snippets.

@ajaydsouza
Last active December 21, 2018 18: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 ajaydsouza/d0ddf2461cebab09cc38eb5ea0697cae to your computer and use it in GitHub Desktop.
Save ajaydsouza/d0ddf2461cebab09cc38eb5ea0697cae to your computer and use it in GitHub Desktop.
Convert Top 10 count to use k, m and bn
<?php
/**
* Modify the display the tptn counter to show k and m instead.
*
* Add this code to your theme's functions.php file or in a file in mu-plugins.
*
* @param $string $input Formatted list count
*/
function tptn_restyle_count( $input ) {
$input = filter_var( $input, FILTER_SANITIZE_NUMBER_INT );
$input = number_format( $input, 0, '.', ',' );
$input_count = substr_count( $input, ',' );
if ( $input_count != '0' ) {
if ( $input_count == '1' ) {
return substr( $input, 0, -4 ) . 'k';
} elseif ( $input_count == '2' ) {
return substr( $input, 0, -8 ) . 'm';
} elseif ( $input_count == '3' ) {
return substr( $input, 0, -12 ) . 'bn';
} else {
return;
}
} else {
return $input;
}
}
add_filter( 'tptn_post_count_only', 'tptn_restyle_count' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment