Add custom text

Our simple widget is technically functional, but it doesn't do anything yet. After you have activated your widget and viewed your homepage, you will see some default text that we pointed out earlier: function WP_Widget::widget() must be over-ridden in a sub-class.

This is the output of the WP_Widget class' widget() function. If we think about our parent/child analogy, here we are getting a message from the parent telling the kid that he needs to take care of this function himself. How do we override the WP_Widget::widget() function? We simply add a widget() function to our ContentRotatorWidget class. Add the following function to the ContentRotatorWidget.php file, somewhere below the __construct() function (remember we like to keep ...

Get WordPress 3 Plugin Development Essentials 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.