Created
December 30, 2013 20:23
-
-
Save kisabelle/8187616 to your computer and use it in GitHub Desktop.
A very simple custom Wordpress widget.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright Widget | |
*/ | |
class my_custom_copyright_widget extends WP_Widget { | |
/** constructor */ | |
function my_custom_copyright_widget() { | |
parent::WP_Widget(false, $name = 'Copyright Text'); | |
} | |
/** @see WP_Widget::widget */ | |
function widget($args, $instance) { | |
extract( $args ); | |
// these are our widget options | |
$text = $instance['text']; // single value | |
$localize_array = array( | |
'text' => $text, | |
); | |
//echo $before_widget; // start widget display code ?> | |
<span class="copyright"> | |
<?php echo $text; ?> | |
</span> | |
<?php | |
} | |
/** @see WP_Widget::update */ | |
function update($new_instance, $old_instance) { | |
$instance = $old_instance; | |
$instance['text'] = strip_tags($new_instance['text']); | |
return $instance; | |
} | |
/** @see WP_Widget::form */ | |
function form($instance) { | |
$text = esc_attr($instance['text']); | |
?> | |
<p> | |
<label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Text:'); ?></label> | |
<textarea rows="3" class="widefat" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>" type="text" value=""><?php echo $text; ?></textarea> | |
</p> | |
<?php | |
} | |
} | |
// register Copyright widget | |
add_action('widgets_init', create_function('', 'return register_widget("my_custom_copyright_widget");')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HI,
Thanks for sharing this code, but I am having troubles using it because the code runs successfully but I don't see any output in the widgets menu. Can you help me out here. Looking forward to hearing from you. Thanks a lot.