只需创建一个新的小部件&;注册它-
/* Create a new Widget */
class WPSE180059_Widget extends WP_Widget
{
public function __construct()
{
$widget_ops = array(
\'classname\' => \'widget_wpse180059\',
\'description\' => __( \'A Custom Widget\')
);
parent::__construct(\'wpse180059\', __(\'WPSE180059 Widget\'), $widget_ops);
}
public function widget( $args, $instance )
{
$title = apply_filters(
\'widget_title\',
empty($instance[\'title\']) ? \'\' : $instance[\'title\'],
$instance,
$this->id_base
);
echo $args[\'before_widget\'];
if ( $title )
{ echo $args[\'before_title\'] . $title . $args[\'after_title\']; }
/* here goes your Shortcode */
echo do_shortcode(\'[example]\');
echo $args[\'after_widget\'];
}
public function update( $new_instance, $old_instance )
{
$instance[\'title\'] = strip_tags($new_instance[\'title\']);
return $instance;
}
public function form( $instance )
{
//Defaults
$title = esc_attr( $instance[\'title\'] ); ?>
<p><label for="<?php echo $this->get_field_id(\'title\'); ?>"><?php _e(\'Title:\'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id(\'title\'); ?>" name="<?php echo $this->get_field_name(\'title\'); ?>" type="text" value="<?php echo $title; ?>" /></p>
<?php
}
}
/* Register your Widget */
function WPSE180059_init() {
register_widget(\'WPSE180059_Widget\');
}
add_action(\'widgets_init\', \'WPSE180059_init\');