How to Update Widget Link Options to Use New Link Group
The new link-group input() type was added in Layers 1.2.12 which replaces the former button link and button text fields in widget repeater areas. The following shows how to update your widgets with the new field, using the Content Widget as a point of reference. Note that line numbers may vary in custom widgets.
Set New Link Variable
Locate the following:
1 2 |
// Set the column link |
Replace with:
1 2 3 4 |
// Get the link array. $link_array = $this->check_and_return_link( $item, 'button' ); $link_href_attr = ( $link_array['link'] ) ? 'href="' . esc_url( $link_array['link'] ) . '"' : ''; $link_target_attr = ( '_blank' == $link_array['target'] ) ? 'target="_blank"' : ''; |
Update Variables in Output
In the widget content section, where output begins around line 250 ( Content Widget Slider Widget ) you must replace each instance of the following variables with the new version:
Linking Featured Media
Old:
1 2 3 |
<?php if( NULL != $link ) { ?><a href="<?php echo $link; ?>"><?php } ?> <?php echo $media; ?> <?php if( NULL != $link ) { ?></a><?php } ?> |
New
1 2 3 4 5 6 7 |
<?php if ( $link_array['link'] ) { ?> <a <?php echo $link_href_attr; ?> <?php echo $link_target_attr; ?>> <?php } ?> <?php echo $media; ?> <?php if ( $link_array['link'] ) { ?> </a> <?php } ?> |
- Condition: if ( $link_array['link'] ){}
- Output URL and url attribute: <?php echo $link_href_attr; ?> = href="http://www.yoursite.com/"
- Output target: <?php echo $link_target_attr; ?> = target="_blank" if the New Tab button is toggled in the control UI.
Linking Titles & Text
This now works the same as linking media.
Old
1 2 3 4 5 6 7 8 9 |
<h5 class="heading"> <?php if( NULL != $link && ! ( isset( $column['link'] ) && $this->check_and_return( $column , 'link_text' ) ) ) { ?> <a href="<?php echo $column['link']; ?>"> <?php } ?> <?php echo $column['title']; ?> <?php if( NULL != $link && ! ( isset( $column['link'] ) && $this->check_and_return( $column , 'link_text' ) ) ) { ?> </a> <?php } ?> </h5> |
New
1 2 3 4 5 6 7 8 9 |
<h5 class="heading"> <?php if ( $link_array['link'] ) { ?> <a <?php echo $link_href_attr; ?> <?php echo $link_target_attr; ?>> <?php } ?> <?php echo $item['title']; ?> <?php if ( $link_array['link'] ) { ?> </a> <?php } ?> </h5> |
- Condition: if ( $link_array['link'] ){}
- Output URL and url attribute: <?php echo $link_href_attr; ?> = href="http://www.yoursite.com/"
- Output Target: <?php echo $link_target_attr; ?> = target="_blank" if the New Tab button is toggled in the control UI.
Creating Buttons
Old
1 2 3 4 5 |
?php if( isset( $column['link'] ) && $this->check_and_return( $column , 'link_text' ) ) { ?> <a href="<?php echo $column['link']; ?>" class="button btn-<?php echo $this->check_and_return( $column , 'design' , 'fonts' , 'size' ); ?>"> <?php echo $column['link_text']; ?> </a> <?php } ?> |
New
1 2 3 4 5 6 7 |
<?php if ( $link_array['link'] && $link_array['text'] ) { ?> <a <?php echo $link_href_attr; ?> class="button btn-<?php echo $this->check_and_return( $item , 'design' , 'fonts' , 'size' ); ?>" <?php echo $link_target_attr; ?>> <?php echo $link_array['text']; ?> </a> <?php } ?> |
- Condition: if ( $link_array['link'] ){}
- Output URL and url attribute: <?php echo $link_href_attr; ?> = href="http://www.yoursite.com/"
- class remains unchanged
- Output Target: <?php echo $link_target_attr; ?> = target="_blank" if the New Tab button is toggled in the control UI.
- Output Button Text: <?php echo $link_array['text']; ?>
Replace Form Element
Old Code:
The Button Link and Button Text fields were previously located near the very end of the Content and Slider Widget and are displayed here for reference in the event your widget follows a custom structure:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<div class="layers-row"> <p class="layers-form-item layers-column layers-span-6"> <label for="<?php echo $this->get_custom_field_id( $widget_details, 'columns', $column_guid, 'link_text' ); ?>"><?php _e( 'Button Link' , 'layerswp' ); ?></label> <?php echo $this->form_elements()->input( array( 'type' => 'text', 'name' => $this->get_custom_field_name( $widget_details, 'columns', $column_guid, 'link' ), 'id' => $this->get_custom_field_id( $widget_details, 'columns', $column_guid, 'link' ), 'placeholder' => __( 'http://' , 'layerswp' ), 'value' => ( isset( $column['link'] ) ) ? $column['link'] : NULL , 'class' => 'layers-text', ) ); ?> </p> <p class="layers-form-item layers-column layers-span-6"> <label for="<?php echo $this->get_custom_field_id( $widget_details, 'columns', $column_guid, 'link_text' ); ?>"><?php _e( 'Button Text' , 'layerswp' ); ?></label> <?php echo $this->form_elements()->input( array( 'type' => 'text', 'name' => $this->get_custom_field_name( $widget_details, 'columns', $column_guid, 'link_text' ), 'id' => $this->get_custom_field_id( $widget_details, 'columns', $column_guid, 'link_text' ), 'placeholder' => __( 'e.g. "Read More"' , 'layerswp' ), 'value' => ( isset( $column['link_text'] ) ) ? $column['link_text'] : NULL , ) ); ?> </p> </div> |
New
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php // Fix widget's that were created before dynamic linking structure. $widget = $this->convert_legacy_widget_links( $widget, 'button' ); ?> <div class="layers-form-item"> <label> <?php _e( 'Insert Link' , 'layerswp' ); ?> </label> <?php echo $this->form_elements()->input( array( 'type' => 'link-group', 'name' => $this->get_layers_field_name( 'button' ), 'id' => $this->get_layers_field_id( 'button' ), 'value' => ( isset( $widget['button'] ) ) ? $widget['button'] : NULL, ) ); ?> </div> |