Skip to content

Instantly share code, notes, and snippets.

@manmar
Created June 23, 2015 08:43
Show Gist options
  • Save manmar/c6d81dbfeb582788872a to your computer and use it in GitHub Desktop.
Save manmar/c6d81dbfeb582788872a to your computer and use it in GitHub Desktop.
A simple WordPress text widget
<?php
class Callout_Widget extends WP_Widget {
function __construct() {
parent::__construct(
'callout_widget', // Base ID
__( 'Widget - Callout', 'text-domain' ), // Name
array( 'description' => __( 'A Simple Callout Widget', 'text-domain' ), ) // Args
);
}
function form( $instance ) {
$callout = isset ( $instance['callout'] ) ? $instance['callout'] : '';
$callout = esc_attr( $callout );
// markup for the form ?>
<p>
<label for="<?php echo $this->get_field_id( 'callout' ); ?>">Callout:</label>
<input class="widefat" type="text" id="<?php echo $this->get_field_id( 'callout' ); ?>" name="<?php echo $this->get_field_name( 'callout' ); ?>" value="<?php echo esc_attr( $callout ); ?>">
</p>
<?php } // instance
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance[ 'callout' ] = strip_tags( $new_instance[ 'callout' ] );
return $instance;
} // update
function widget( $args, $instance ) {
$clot = $instance['callout'];
// check if $clot has values
if( $clot ) { ?>
<section class="callout">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-lg-10 col-lg-offset-1">
<p><?php echo $clot; ?></p>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</section><!-- /.callout -->
<?php }
} // widget
} // class
function register_callout_widget() {
register_widget( 'Callout_Widget' );
}
add_action( 'widgets_init', 'register_callout_widget' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment