How to make a widget that has one textbox and custom html output in WordPress.
This has to go to top of your plugin file, wordpress uses this to identify the plugin. You can change te variables as you please.
Source code viewer
<?php /** * Bootstrap file for the plugin. * * @package My Widget * * @wordpress-plugin * Plugin Name: My Plugin * Plugin URI: http://browse-tutorials.com * Description: My plugin description * Version: 1.0.0 * Author: Browse-Tutorials * Author URI: http://browse-tutorials.com * License: GPL-2.0+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt */ ?>Programming Language: PHP
Simple widget with one text field in the form and it displays the content of that textbox.
Source code viewer
<?php /** * Create a class for the widget. */ class My_text_Widget extends WP_Widget { /** * Sets up a new instance of the widget. */ public function __construct() { parent::__construct( // Optional Base ID for the widget, lower case, if left empty a portion of the widget's class name will be used. Has to be unique. 'widget', // Name for the widget displayed on the configuration page. __( 'My first widget', 'my_locale' ), $widget_ops ); } /** * Outputs the content for the current widget instance. * @param array $args Display arguments including 'before_title', 'after_title', * 'before_widget', and 'after_widget'. * @param array $instance Settings for the current Search widget instance. */ function widget( $args, $instance ) { // http://phpdoc.wordpress.org/trunk/WordPress/Widgets/WP_Widget.html#widget echo $text; } } /** * This function should check that $new_instance is set correctly. The newly * calculated value of $instance should be returned. If "false" is returned, * the instance won't be saved/updated. * @param array $new_instance * @param array $old_instance * @return array */ function update( $new_instance, $old_instance ) { // http://phpdoc.wordpress.org/trunk/WordPress/Widgets/WP_Widget.html#update $instance = $old_instance; return $instance; } /** * Widget form on widgets page in admin panel. * @param array $instance * @return void */ function form( $instance ) { echo ' <p><label for="' . $this->get_field_id( 'text' ) . '"> Text: <input class="widefat" id="' . $this->get_field_id( 'text' ) . '" name="' . $this->get_field_name( 'text' ) . '" type="text" value="' . attribute_escape( $text ) . '" /> </label></p>'; } } // Load your widget into WordPress. add_action( 'widgets_init', 'my_text_widget_init' ); function my_text_widget_init() { register_widget( 'My_text_Widget' ); }Programming Language: PHP