The Widget Init is a PHP function that is used to register and initialize WordPress widgets. It is generally used in WordPress theme development to enable the use of custom widgets that can be added to the sidebar or other areas of the website.
Example 1:
// Register custom widget function register_custom_widget() { register_widget('Custom_Widget'); }
// Initialize custom widget class Custom_Widget extends WP_Widget {
function __construct() { parent::__construct( 'custom_widget', __('Custom Widget', 'text_domain'), array('description' => __('A custom widget for displaying recent posts.', 'text_domain')) ); }
public function widget($args, $instance) { // Widget code here }
}
In this example, the PHP function Widget Init is used to register a new custom widget called "Custom_Widget". The widget is created as a custom class that extends the built-in WP_Widget class, and it includes a description and code for displaying recent posts.
Package Library: WordPress core functions and classes.
Example 2:
// Register custom widget function register_custom_widget() { register_widget('Custom_Widget'); }
// Initialize custom widget class Custom_Widget extends WP_Widget {
function __construct() { parent::__construct( 'custom_widget', __('Custom Widget', 'text_domain'), array('description' => __('A custom widget for displaying social media links.', 'text_domain')) ); }
public function widget($args, $instance) { // Widget code here }
}
In this example, a Widget Init function is used to register another custom widget called "Custom_Widget". This widget is designed to display social media links, and it includes a description and code for achieving this functionality.
Package Library: WordPress core functions and classes.
PHP Widget::init - 30 examples found. These are the top rated real world PHP examples of Widget::init extracted from open source projects. You can rate examples to help us improve the quality of examples.