How to show Widget ID in WordPress theme and WordPress Admin

This tip will help you how to show Widget ID in WordPress theme and WordPress Admin by using simple PHP function.

Using php code to get Widget ID

1. Open your folder theme
2. Edit functions.php file
3. Insert below code to functions.php

add_action('in_widget_form', 'vnt_get_widget_id');

function vnt_get_widget_id($widget_instance)

{
    // Check if the widget is already saved or not. 
    
    if ($widget_instance->number=="__i__"){
     
     echo "

<strong>Widget ID is</strong>: Pls save the widget first!

"   ;
    
    
  }  else {

        
       echo "

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

";
         
 
    }
}

4. Save and reload your widget in WordPress Dashboard. You will see the ID of Widget

Show Widget ID in WordPress theme

Share this :

No comments yet.

Leave a Reply

Related post

Free Responsive Website templates

ThemeVina is Best site for free sharing and download Wordpress themes, Joomla templates, Responsive website templates and more HTML templates.

All template in Site are free. You can download and install for your site.

Contact us

  • Brand: Theme Vina
  • Email: admin@themevina.com
  • Website: www.themevina.com
  • Address: 367 Tran Hung Dao Street
  • Location: Thai Binh City, Thai Binh, Viet Nam

Newsletter