How to get Widget ID in WordPress

If you’re working on your own theme or maybe customizing one the best themes for WordPress, if you are developing your own plugin or setting up another one, you might need a widget ID to make everything work as it should.

For example, you can easily show/hide a widget on a specific page, but you will have to provide a widget ID to make the code work. Finding the ID actually isn’t that hard, but if you have to find one more often than not, code/plugin in this article might save you some trouble.

In today’s article, we will show you few simple methods of finding a widget ID.

If you only have to find a widget ID for one widget, for one time, you won’t be needing a plugin or the code. Just follow these few simple steps and read an ID for yourself.

Find widget ID:

  1. Open Appearance->Widgets
  2. On top of the screen, find “Screen Options” and open it
  3. Click on “Enable Accessibility Mode”
  4. Find a widget for which you want to know ID and click the “Edit” button
  5. In the address bar, find “editwidget=something” where “something” is the ID you are looking for

If you are searching for a much cleaner solution, keep on reading.

Instead of reading the ID for each and every widget, you can display the ID under each widget in its options. You can do that by installing a plugin or you can copy the code you will find below.

Install a plugin:

  1. Go to Plugins->Add New
  2. Search for “Get Widget ID”
  3. Install and activate the plugin
  4. Go to Appearance->Widgets and open any widget from your list. On bottom of the widget, you will find a widget ID

Get Widget ID plugin is as simple as it can be, but sometimes you don’t want yet another plugin on your list. The developer of the plugin was kind enough to provide the source code used in the plugin and we are going to show you the code here. After you install the code and save the changes, you will get the same result as installing the plugin – widget ID will be shown just under all its settings.

Copy the code:

  1. Open functions.php file
  2. Copy and paste the following code:
  3. add_action('in_widget_form', 'spice_get_widget_id');
    function spice_get_widget_id($widget_instance)
    // Check if the widget is already saved or not.
    if ($widget_instance->number=="__i__"){
    echo "<p><strong>Widget ID is</strong>: Please save the widget</p>"   ;
    }  else {
    echo "<p><strong>Widget ID is: </strong>" .$widget_instance->id. "</p>";
  4. Save changes
  5. Go to Appearance->Widgets and select a widget to see if the function has displayed the ID.

If you need to find an ID for a page, post, user, etc., see how to how to find and display an ID in WordPress.

That’s it. After you install the plugin or create the function by yourself, you won’t be having problems finding the widget ID. Sometimes simple “tricks” can make your work much faster and easier, right?

If you are interested in more WordPress tricks like this, don’t forget to stop by our WordPress section where you can learn more about the popular CMS.

Start Blog Book


This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

One thought on “How to get Widget ID in WordPress

  1. Is it important to know the id number for CSS styling? I am trying to understand how to decide on CSS IDs or elements. I understand a little bit, but I feel like I need to get the boundaries.

Leave a Reply

Your email address will not be published. Required fields are marked *