Why is my custom WordPress widget not working?

Sophus May 24, 2012
Pinterest Stumbleupon Whatsapp
Ads by Google

I read this article: //www.makeuseof.com/tag/how-to-create-wordpress-widgets/ How To Create Your Own Basic Wordpress Widgets How To Create Your Own Basic Wordpress Widgets Many bloggers will search for the perfect Wordpress widget that will do exactly what they want, but with a little programming experience you may find it's easier to write your custom widget. This week I'd... Read More about how to create WordPress widgets. Everything went fine until this error page came out in my website:

Fatal error: Class 'RandomPostWidget' not found in C:\xampp\htdocs\sowhat\wp-includes\widgets.php on line 324

I sort of understand the problem, but I dont know how to fix it. In line 324, this is the code:

$this->widgets[$widget_class] = new $widget_class();

I think this happened because I changed the ‘Random Post Widget’ words to ‘News Widget’, including the class name. Maybe I did somthing wrong? Any help would be greatly appreciated!

  1. muotechguy
    May 25, 2012 at 7:35 am

    I should answer that since its my article... could you post your full code so we can see where you missed? The error implies the class name hasn't been changed everywhere its needed. Maybe just do a full text search and replace for 'RandomPostWidget' to 'NewsWidget'?