How to Show WordPress Widgets Only to Logged In Users

Ever need to show a WordPress widget only to logged in users? Or maybe you have the opposite need: you want to show a widget only to users who are NOT logged in.

In this post, we’ll go over how to do both.

show-hide


Using Widget Logic

Widget Logic is a very popular plugin that will help us accomplish our goal. While Widget Logic can help you do much more than hide or show a widget to logged in/logged out users, we’re going to focus this post on that particular task.

Once installed and activated, you will see an empty box at the bottom of each widget. (Appearance > Widgets)

widget-logic-menu-blank

In order to show a widget only to certain users, you will need to put some code in the box.

Of course there are two basic choices you have here:

1. Show widget only to users who ARE logged in:

is_user_logged_in()

2. Show widget only to users who are NOT logged in

Same code as above, but put an exclamation point (!) before it:

!is_user_logged_in()

Here’s a look with the first bit of code in the box.

widget-logic-menu

And here we can see this menu appearing only for logged in users.

widget-logic-logged-in-users

As mentioned, Widget Logic will allow you to create lots of other conditional statements besides this one. You can see the plugin page (or search the web) for other pieces of code to insert.

Photo credit: gfpeck

Tags

Comments (3)

  1. It works great, once you get the hang of it, and once you get a full listing of all the various inputs. You should attach that listing Joe :))

    But for most newbies, both Dynamic Widgets and Visual Widget Logic are much simpler to use and get the same job done.

Participate