Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maxsherlock/5dca86fd604d827f49e6e7399db80183 to your computer and use it in GitHub Desktop.
Save maxsherlock/5dca86fd604d827f49e6e7399db80183 to your computer and use it in GitHub Desktop.
This adds a simple custom-widget.php in your CHILD theme wp-content directory. Add the HTML code to the page you want your widget to appear: <form method='post' action="custom-widget.php"> <p class="submit"> <input type="submit" class="button-primary" value="submit" /> </p> </form>
/**
* Sets up the custom widget name etc
*/
public function __construct() {
 // widget actual processes
}

/**

  • Outputs the content of the custom widget
  • @param array $args
  • @param array $instance */ public function widget( $args, $instance ) { // outputs the content of the custom widget }

/**

  • Outputs the options form on admin
  • @param array $instance The custom widget options */ public function form( $instance ) { // outputs the options form on admin }

/**

  • Processing custom widget options on save
  • @param array $new_instance The new options
  • @param array $old_instance The previous options / public function update( $new_instance, $old_instance ) { // processes widget options to be saved } }
    /
    // Start by adding the following to your page where you want the widget to appear: //

// Create a new php file entitled custom-widget.php in your CHILD theme wp-content directory

Some background on this custom widget plugin and an example:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment