How to get the Widget ID in WordPress

If you are customizing the WordPress theme or working on your own theme, you might need a widget ID to make everything work like you want. For example, if you want to hide the widget on a specific page, you will need to provide a widget ID to make the code work. In this tutorial, we will show you how to get the widget ID in WordPress.

Get the widget ID without code and plugin

Follow the steps below to get 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 the widget for which you want to know ID and click the “Edit” button.
  5. In the address bar, find “editwidget=something”, this “something” is the widget ID.

Get the widget ID with code

If you want to get the widget ID with the code follow the steps below.

Open functions.php file and copy and paste the following code:

add_action('in_widget_form', 'tricks_get_widget_id');
function tricks_get_widget_id($widget_instance){
    if ($widget_instance->number=="__i__"){
		echo "

Please save the widget

"   ;
    }  else {
		echo "

<strong>Widget ID is: </strong>" .$widget_instance->id. "


Now go to Appearance->Widgets and select a widget to see the widget ID.