Ready to get started?Download WordPress


Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/zeroise


Add leading zeros when necessary.

If you set the threshold to '4' and the number is '10', then you will get back '0010'. If you set the threshold to '4' and the number is '5000', then you will get back '5000'.

Uses sprintf to append the amount of zeros based on the $threshold parameter and the size of the number. If the number is large enough, then no zeros will be appended.


<?php zeroise$number$threshold ); ?>


(mixed) (required) Number to append zeros to if not greater than threshold.
Default: None
(integer) (required) Digit places number needs to be to not have zeros added.
Default: None

Return Values

Adds leading zeros to number if needed.


Leading Zeros on Number of Comments

This example allows you to add leading zeros to the number of comments (used within the loop). In the particular example shown below, the threshold is set to 2, so single digit numbers will have a zero added, and numbers in the tens and higher will not. For example, 1 will be displayed as 01.

    $comno = get_comments_number();
    echo zeroise($comno, 2);


Change Log

Since: 0.71

Source File

zeroise() is located in wp-includes/formatting.php.


See also index of Function Reference and index of Template Tags.