Last active
January 7, 2018 22:50
-
-
Save ovizii/3891aff7c1db38b96349 to your computer and use it in GitHub Desktop.
Create discreet widget - only shows if not empty
This file contains hidden or 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
//add discreet text widget | |
add_action('widgets_init', 'custom_discreet_text_widget'); | |
function custom_discreet_text_widget() { | |
class DiscreetTextWidget extends WP_Widget_Text { | |
function DiscreetTextWidget() { | |
$widget_ops = array('classname' => 'discreet_text_widget', 'description' => __('Arbitrary text or HTML, only shown if not empty')); | |
$control_ops = array('width' => 400, 'height' => 350); | |
$this->WP_Widget('discrete_text', __('Discreet Text'), $widget_ops, $control_ops); | |
} | |
function widget( $args, $instance ) { | |
extract($args, EXTR_SKIP); | |
$text = apply_filters( 'widget_text', $instance['text'] ); | |
if (empty($text)) return; | |
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']); | |
echo $before_widget; | |
if (!empty($title)) { echo $before_title.$title.$after_title;} ?> | |
<div class="textwidget"><?php echo $instance['filter'] ? wpautop($text) : $text; ?></div> | |
<?php | |
echo $after_widget; | |
} | |
} | |
return register_widget("DiscreetTextWidget"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment