Display User Points

Displaying the Points Directly #

To display the points directly, use the wordpoints_display_points() function. You just need to provide it the user’s ID, the slug of the points type, and a “context” string. (The context string is used to differentiate between the different places where points are displayed. This allows the points value to be formatted differently in different contexts.)

It would look something like this:

There is no need to use echo, because wordpoints_display_points() calls echo internally.

Display the Current User’s Points #

To display the current user’s points, you can use get_current_user_id():

If the user is not logged in, nothing will be displayed.

Displaying the Points Indirectly #

Sometimes you need to get the points value so that you can pass it to another function that will do the job of displaying it. Because wordpoints_display_points() calls echo directly, it won’t work in a situation like that. Instead, you need to use wordpoints_get_formatted_points():

The value returned by wordpoints_get_formatted_points() will be automatically formatted for display with the prefix and/or suffix for that type of points.

Display the Current User’s Points #

To display the current user’s points, you can use get_current_user_id():

If the user is not logged in, the function will return false, which will display as 0. If you want to display nothing when the user isn’t logged in, you would do something like this: