I've created widget by simple copying one of the default widgets class and modifying it.
The strange thing is in the widgets admin area, this widget is not shown. When I searched the page source code the widget was there but it had inline style display:none;.
The other weird thing is that the title filed is not shown either!
Here is my widget code:

 * Mood widget class
class WP_Widget_Mood extends WP_Widget {

    function __construct() {
        $widget_ops = array('classname' => 'widget_mood', 'description' => __( "Mood widget") );
        parent::__construct('mood', __('Mood'), $widget_ops);

    function widget($args, $instance){
        $title = apply_filters('widget_title', empty($instance['title']) ? 'Mood' : $instance['title'], $instance, $this->id_base ); 

        $user_id = get_current_user_id();

        $table_name = $wpdb->prefix . "mood";

        $get_same=$wpdb->get_row("SELECT * FROM $table_name where user_id='".$user_id."' order by id desc");
        $get_mood_row = mysql_query("select * from wp_mood where user_id='".$user_id."' and mood='".$get_same->mood."'");
        $pathredirect = get_bloginfo('url').'/m/'.$current_user->user_nicename.'/settings/mood/';
        global $current_user;
        $current_user = wp_get_current_user();

        <h3 class="sideheading"><?php echo $title; ?></h3>
        <dl id="settingss" class="dropdown3">
                <a title="Options" href="#setting">
                    <div id="rightsetting" class="sprite"></div>
                    <li><p id="wlcmstg2" class="sprite"></p><a href="#Make">Make</a></li>
                    <li><p id="wlcmstg1" class="sprite"></p><a href="<?php echo $pathredirect;?>">Setting</a></li>

        <div id="charectersbar">
            <div id="prev"><span id="go-prev2" class="sprite"> </span></div><!--#prev-->
            <div id="slide">
                <div id="slider2">
                        //echo "select * from wp_mood where user_id!='".$user_id."' and mood='".$get_same->mood."'";
                        $res_mood = mysql_query("select * from wp_mood where user_id='".$user_id."' and mood='".$get_same->mood."'");
                        while($result_mood = mysql_fetch_array($res_mood)){
                            $uuserid = $result_mood['user_id'];
                            $user_info = get_userdata($uuserid);
                                <a href="<?php echo bloginfo('url');?>/m/<?php echo $current_user->user_nicename; ?>/profile">
                                    <img title="<?php echo $result_mood['nikename'];?>" src="<?php echo bloginfo('url').'/wp-content/uploads/mood/'.$result_mood['image'];?>" /><?php echo $result_mood['nikename'];?>

                    <?php } ?>
            <div id="next">
                <span id="go-next2" class="sprite"></span>

    function form( $instance ) {
        $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
        $title = $instance['title'];
        <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>

    function update( $new_instance, $old_instance ) {
        $instance = $old_instance;
        $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
        $instance['title'] = strip_tags($new_instance['title']);
        return $instance;

function mytheme_register_widgets()
    register_widget( 'WP_Widget_Mood' );

add_action( 'widgets_init', 'mytheme_register_widgets' );

1 Answer 1


I am not seeing you registering the widget in this code.

For inside of a theme: register_widget('WP_Widget_Mood');

For inside of a plugin: add_action( 'widgets_init', create_function('', 'return register_widget("WP_Widget_Mood");') );

  • Yes, I do register the widget. The mentioned widget along with 2 other widgets. I updated the code. But that's not really my problem.
    – 2hamed
    Commented Jul 2, 2012 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.