How to Create New Custom Widget ?
Standard Practice to Create Widget
/***Widget for Welcome Box *********/
class Welcome extends WP_Widget {
/**
* Sets up the widgets name etc
*/
public function __construct() {
// widget actual processes
parent::__construct(
'welcome_user', // Base ID
__('Welcome User', 'text_domain'), // Name
array( 'description' => __( 'Shows Welcome Message if User is Logged In', 'text_domain' ), ) // Args
);
}
/**
* Outputs the content of the widget
*
* @param array $args
* @param array $instance
*/
public function widget( $args, $instance ) {
// outputs the content of the widget
if(is_user_logged_in())
{
$objCurrentUser = wp_get_current_user();
$strNiceName = $objCurrentUser->data->user_nicename;
?>
<div class="welcome_text">
<?php echo __('Welcome '.$strNiceName); ?>,
<a href="<?php echo wp_logout_url(get_option('siteurl')); ?>"><?php echo __('Log Out'); ?></a>
</div>
<?php
}
}
/**
* Ouputs the options form on admin
*
* @param array $instance The widget options
*/
public function form( $instance ) {
// outputs the options form on admin
}
/**
* Processing widget options on save
*
* @param array $new_instance The new options
* @param array $old_instance The previous options
*/
public function update( $new_instance, $old_instance ) {
// processes widget options to be saved
}
}
add_action('widgets_init', 'fnWelcome');
function fnWelcome(){
register_widget( 'Welcome' );
}
/********** END **********/
Another Way to Create Widget
register_sidebar_widget(<Widget Title>, <your Custom function name>);
A blogger
I am passionate blogger cum B.Tech. Computer engineering graduate. I love writing blog post. I spend my free time in writing blog post that will useful to everyone (including me). I have had some success making money blogging and want to help others do the same. I just figured that by creating a great and free resource a lot of links would follow – and they have. Some people ask me how they can repay me – which is not necessary - but for those wanting to show their appreciation, I just say linking to the article from their blog is the best compensation I could receive. Thanks for reading!
0 comments:
Post a Comment
Thanks for commenting. I will Reply you soon