• Skip to primary navigation
  • Skip to main content
OsomCode

OsomCode

Awesome code tutorials for WordPress and Genesis

  • Subscribe
  • My account
    • Edit profile
    • Favorites
    • Update credit card
  • Login

Display a list of WordPress users of your choice

Discover in this tutorial how to create a shortcode that allows you to display a list with the WordPress users you want.

In previous tutorials you have seen how to create a loop of users depending on their role or if they have an active subscription.

But it is possible that in some situation you want to display a list of users chosen or filtered by you.

So in this tutorial you are going to see how to create a shortcode that allows you to enter the identifiers of the users you want to display.

This would be the final result:

List of specific WordPress users
List of specific WordPress users

Shall we?

Steps to display a list of WordPress users according to their IDs

1. Create the shortcode

Add the following code snippet to your functionality plugin:

To see this and another 883 code snippets of this website, login or subscribe here.

With this code you create a loop with the users that you specify in the shortcode id parameter, showing the following elements:

  • Image (avatar)
  • Name

This is just an example. You can add or remove the fields you consider necessary using the function get_user_meta.

In the loop arguments you indicate:

  • The users you want to be displayed within the parameter id
  • To be sorted by name

You can modify the arguments you consider necessary.

2. Customize the CSS of the subscribers list

Now you just need to assign the styles to make it look the way you want.

To do this, insert this block at the end of style.css:

To see this and another 883 code snippets of this website, login or subscribe here.

When creating the shortcode you have used the classes users-wrapper and user, which allow you to layout the listing as you wish.

With these few lines of CSS you can make it look like the example I showed you at the beginning. But, as always, I invite you to customize it to your liking.

3. Add the shortcode where you want to display the list of users

Finally, create the page where you want to display the list of subscribers and add the shortcode [usuarios id="x,y,z"] where you replace the letters by the user identifiers. For example: [usuarios id="12,33,54,88"].

You can get the user ID by checking the URL when you edit it or, if you want to make it easier, get it displayed directly in the WordPress admin with this tutorial.

Conclusions

Now you know how to display a list with the WordPress users you want thanks to a shortcode with parameters.

If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.

Benefits of being a subscriber. 🙂

CSS PHP WordPress

To leave read and make questions about this code, you can login or register.

  • About OsomCode
  • FAQ
  • Contact

Legal Notice · Privacy Policy · Cookie Policy · Terms and conditions
Copyright © 2023

Lost your password?