Insert After Each Label in Radio Box Group

Support General Insert After Each Label in Radio Box Group

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1390
    JustinJustin
    Participant

    Is there a filter that will allow me to insert a break tag after each label in a radio box group (one radio box group only, so by Field ID)? If so, how do I use it? Thanks.

    #1394
    Anh TranAnh Tran
    Keymaster

    I think the best way to do that is via CSS. You can install a plugin like Add admin CSS. The CSS to make each label display in ins own line is quite simple:

    .rwmb-radio-wrapper .rwmb-input > label {
      display: block;
    }

    If you don't want to use a plugin, you can enqueue a CSS file on Add new/Edit page with the same snippet above.

    This way you also can add more margin to label for a better look.

    But if you have to use PHP to output line break after each label tag, please use rwmb_radio_html filter, like this:

    add_filter( 'rwmb_radio_html', function html( $output, $field, $meta )
    {
    	$html = array();
    	$tpl  = '<label><input type="radio" class="rwmb-radio" name="%s" value="%s"%s> %s</label>';
    
    	foreach ( $field['options'] as $value => $label )
    	{
    		$html[] = sprintf(
    			$tpl,
    			$field['field_name'],
    			$value,
    			checked( $value, $meta, false ),
    			$label
    		);
    	}
    
    	return implode( '<br>', $html );
    }, 10, 3 );
    #1397
    JustinJustin
    Participant

    OK. Thanks, Anh.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Insert After Each Label in Radio Box Group’ is closed to new replies.