Reusable Text Blocks
[resolved] Feature: Optionally hide widget title on front-end (3 posts)

  1. ten9inc
    Posted 2 years ago #

    I use this plugin primarily for sidebar widgets. I have the need, on several sites which use your plugin, to hide some or all of the Text Blocks Widget titles on the front end of the site.

    I could not figure out how to do it automatically with a filter, so I hacked the plugin to add a second checkbox on the Widgets admin screen: Hide widget title on front end. When checked, the widget title and surrounding tags are not printed out in the rendered page.

    Please have a look and maybe it is something you could incorporate into the plugin, since it only added 6 lines and I think there might be a general use for this.

    function widget($args, $instance)
            extract( $args );
            $title 		= isset($instance['title']) ? $instance['title'] : false;
            $id 		= (int) $instance['id'];
            $block 		= get_post( $id );
            $wpautop	= isset($instance['wpautop']) ? $instance['wpautop'] : false;
            $show_title = isset($instance['show_title']) ? $instance['show_title'] : false;
            $block_content = $block->post_content;
            if($wpautop == "on") { $block_content = wpautop($block_content); }
              <?php echo $before_widget; ?>
                  <?php if ( $title && !$show_title ) echo $before_title . $title . $after_title; ?>
    				<div class="text-block <?php echo $block->post_name ?>"><?php echo apply_filters( 'text_blocks_widget_html', $block_content); ?></div>
              <?php echo $after_widget; ?>
        function update($new_instance, $old_instance)
    		$instance = $old_instance;
    		$instance['title'] 		= strip_tags($new_instance['title']);
    		$instance['id'] 		= strip_tags($new_instance['id']);
    		$instance['wpautop'] 	= strip_tags($new_instance['wpautop']);
    		$instance['show_title'] = strip_tags($new_instance['show_title']);
            return $instance;
        function form($instance)
            $title = isset($instance['title']) ? esc_attr($instance['title']) : "";
            $selected_block = isset($instance['id']) ? esc_attr($instance['id']) : 0;
            $wpautop = isset($instance['wpautop']) ? esc_attr($instance['wpautop']) : 0;
            $show_title = isset($instance['show_title']) ? esc_attr($instance['show_title']) : 0;
            $blocks = get_posts( array('post_type' => 'text-blocks', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ));
              <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; ?>" />
              <label for="<?php echo $this->get_field_id('id'); ?>"><?php _e('Text Block:'); ?></label>
              <select class="widefat" id="<?php echo $this->get_field_id('id'); ?>" name="<?php echo $this->get_field_name('id'); ?>">
              	<?php foreach($blocks as $block) { ?>
              	<option value="<?php echo $block->ID; ?>"<?php if($selected_block == $block->ID) echo " selected=\"selected\""; ?>><?php echo $block->post_title; ?></option>
              	<?php } ?>
    			<input id="<?php echo $this->get_field_id('wpautop'); ?>" name="<?php echo $this->get_field_name('wpautop'); ?>" type="checkbox"<?php if($wpautop == "on") echo " checked='checked'"; ?>>&nbsp;
    			<label for="<?php echo $this->get_field_id('wpautop'); ?>">Automatically add paragraphs</label>
    			<input id="<?php echo $this->get_field_id('show_title'); ?>" name="<?php echo $this->get_field_name('show_title'); ?>" type="checkbox"<?php if($show_title == "on") echo " checked='checked'"; ?>>&nbsp;
    			<label for="<?php echo $this->get_field_id('show_title'); ?>">Hide widget title on front end</label>


  2. Hal Gatewood
    Plugin Author

    Posted 2 years ago #

    I like it. I have a few other things to add to this plugin that people have submitted. I hope to get to it soon.

    Thanks for the work!

  3. Hal Gatewood
    Plugin Author

    Posted 1 year ago #

    I just added in version 1.4.6 however I called it hide_title. I felt that show_title should be the default and hiding it would be the option.

    Hope that helps. Thanks for your work!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Reusable Text Blocks
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic