I want to add widgets to my wordpress site programmatically. I tried the following code from the codex docs:
class MyNewWidget extends WP_Widget {
function MyNewWidget() {
// Instantiate the parent object
parent::__construct( false, 'My New Widget Title' );
}
function widget( $args, $instance ) {
// Widget output
}
function update( $new_instance, $old_instance ) {
// Save widget options
}
function form( $instance ) {
// Output admin widget options form
}
}
function myplugin_register_widgets() {
register_widget( 'MyNewWidget' );
}
add_action( 'widgets_init', 'myplugin_register_widgets' );
But doesn’t seem to work. I even tried the code from the question Programmatically add widgets to sidebars but to no avail. Please tell me if I am missing out something.
Thankyou
Because your code is just like prototype, it doesn’t display anything.
That’s why your are not seeing anything in dashboard.
I just copied this code from wordpress.org but you can modify it to your need
.Reply if you need more help
here is an example that should work with the latest version of wordpress: