Creating a custom widget in WordPress is pretty easy and is a great way to allow users to modify their sidebar content. In this example we’ll create a widget that displays some copy and then renders a link to another page on the site. If you’re unfamiliar with WordPress widgets, the Widgets API Codex Reference is very helpful.

The first step is to create the widget class.

The important function here is form(). This renders the form for the widget. We display a textarea and then use get_pages to get all of the pages on the site. We use that array of pages to create a dropdown menu for users to simply choose a page on the site without the need to code a link element.

In functions.php register the widget.

Your widget is now ready to add in wp-admin.