How to include checkbox in widget backend form?

First, on function widget: function widget( $args, $instance ) { extract( $args ); // Add this line $your_checkbox_var = $instance[ ‘your_checkbox_var’ ] ? ‘true’ : ‘false’; // Change ‘your_checkbox_var’ for your custom ID // … } On function update: function update( $new_instance, $old_instance ) { $instance = $old_instance; // Add this line $instance[ ‘your_checkbox_var’ ] … Read more

Programmatically add widgets to sidebars

When I started this answer it should be just a small note. Well, I failed. Sorry! Stay with me, there is a goody hidden deep down … How WordPress widgets are stored The list of widget is stored in an option named ‘sidebars_widgets’. A var_export() may give something like the following: array ( ‘wp_inactive_widgets’ => … Read more

Between functions.php (theme), widgets, and plugins, which is loaded first?

The plugins are loaded right before theme (yes, I’ve been looking for excuse to use this): However it is wrong to think about either as point of code execution. For most cases everything should be hooked and executed no earlier than init hook. According to Codex widget registration with register_widget() should be hooked to widget_init. … Read more

Where to put my code: plugin or functions.php?

I would start with this question: Is the functionality related to presentation of content, or with generation/management of content, or of the site, or of the user identity? If the functionality is not related specifically to presentation of content, then it is squarely within Plugin Territory. This list is long: Modifying core WP filters (wp_head … Read more