Recent Entries

This blog is a collection of some useful code snippets I've worked on. Some of the items are probably a little more obscure than others, but there's always somebody out there looking for an obscure solution.

WordPress: Check if a User Has a Specific Role

The default current_user_can() and user_can() functions are adequate for checking if a user belongs to a role, but I find the function names confusing.  Also, those functions check both roles and capabilities, which seems inefficient if one only needs to check the role. This function does one thing only: check if a user belongs to… Read more »

WordPress: Add Login and Logout links to Menus

This snippet will add a “Log In” link for logged-out users, and a “Log Out” link for logged-in users.  In this example, it is using the theme locations “main-nav” and “footer-links” as identifiers.  Change those values to match the locations of the menu(s) that you want to use.  The user’s first name or display name… Read more »