Last active
December 21, 2018 18:39
-
-
Save ajaydsouza/d0ddf2461cebab09cc38eb5ea0697cae to your computer and use it in GitHub Desktop.
Convert Top 10 count to use k, m and bn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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