Reputation: 1384
I'm building my first WordPress custom widget and I have I doubt at this point. So far this is the structure of my widget
<?php
//Add an action that will load all widgets
add_action( 'widgets_init', 'ma_load_widgets' );
//Function that registers the widgets
function ma_load_widgets() {
register_widget('ma_my_widget');
}
/*-----------------------------------------------------------------------------------
Plugin Info : Goes here
-----------------------------------------------------------------------------------*/
class ma_my_widget extends WP_Widget {
function ma_my_widget (){
code_goes_here
}
function widget($args, $instance){
extract($args);
code_goes_here
}
function update($new_instance, $old_instance){
$instance = $old_instance;
code_goes_here
return $instance;
}
function form($instance){
code_goes_here
}
}
?>
I have saved this code into a widget.php file and placed into includes folder, I am working on WP 3.5 Twenty twelve but when I am going to widgets in my backend I don't see it. What am I doing wrong?
Upvotes: 0
Views: 198
Reputation:
You have to put your widget into a folder in wp-content\plugins
for any other question check here :
http://codex.wordpress.org/Widgets_API
Upvotes: 1
Reputation: 16729
I have saved this code into a widget.php file and placed into includes folder
That's wrong. Add "plugin headers" at the top of your widget.php file, like:
<?php
/*
Plugin Name: Ma My Widget :)
Description: My widget
Version: 1.0
Author: Me
License: GPL2
*/
?>
Put the file in your plugins folder, and then you'll see it listed in the plugins page from your dashboard. Activate it and you'll also see your widget in the dashboard
Check out their Plugin API and the Widget API
Upvotes: 1