Sometimes you want a quick way to create a WordPress widget to easily drop a piece of code in the sidebar for easy maneuverablility. These widgets have no options or input fields in the appearance > widgets backend. When you add these widgets to the sidebar, it instead says “There are no options for this widget.”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
/* Blank Widget Template */ /** Register Widget **/ function blank_load_widgets() { register_widget( 'blank_Widget' ); } add_action( 'widgets_init', 'blank_load_widgets' ); /** Define the Widget as an extension of WP_Widget **/ class blank_Widget extends WP_Widget { function blank_Widget() { /* Widget settings. */ $widget_ops = array( 'classname' => 'widget_blank', 'description' => 'This is the description of your blank widget template.' ); /* Widget control settings. */ $control_ops = array( 'id_base' => 'blank-widget' ); /* Create the widget. */ $this->WP_Widget( 'blank-widget', 'Blank Widget Title', $widget_ops, $control_ops ); } function widget( $args, $instance ) { ?> [ADD THE CODE YOU WOULD LIKE TO DUMP IN THE SIDEBAR HERE] <?php } } |