How to do it...

Follow these steps to create a new widget and add it to the Widgets section:

  1. Open the wp-content/themes/twentytwentychild folder of your WordPress installation and open the functions.php file.
  2. Add the following code at the end to define the basic structure of a widget:
class WP_Widget_Product_Pages extends WP_Widget { public function __construct() { $widget_ops = array( 'classname' => 'widget_product_pages', 'description' => __( 'Pages with Product Landing Page Template.'  ), ); parent::__construct( 'product-pages', __( 'Product Pages' ),  $widget_ops ); } public function form( $instance ) { // Code in Step 3 should be added in the next line } public function widget( $args, $instance ) {  // Code in Step 4 should be added ...

Get WordPress 5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.