Josh Guss

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • in reply to: Adding custom classes to widget wrapper #101631
    Josh Guss
    Participant

    Hey Daron,

    Meant to respond earlier but just haven’t had the chance. Prior to seeing your response I ended up working it out by doing it in the functions.php file globally for all widgets and seems to be working well for my purposes so far. For reference, the code i’m using is:

    add_filter('dynamic_sidebar_params', 'before_widget_custom_classes');
    function before_widget_custom_classes( $params ) {
    	
    	// get widget vars
    	$widget_id = $params[0]['widget_id'];
    
    	$hide_title = get_field('hide_title', 'widget_' . $widget_id);
    	$border_color = get_field('border_color', 'widget_' . $widget_id);
      $custom_color = get_field('color', 'widget_' . $widget_id);
    	$no_padding = get_field('remove_padding', 'widget_' . $widget_id);
    	$col_width = get_field('column_width', 'widget_' . $widget_id);
    
    	if ( $no_padding == 1 ) {
    		$no_padding_class = 'no-padding';
    	}
    
    	if ( $hide_title == 1 ) {
    		$hide_title_class = 'no-title';
    	}
    	
    	if( $col_width || $border_color || $no_padding || $hide_title) {
    		
    		$params[0]['before_widget'] = preg_replace( '/class="widget/', "class=\"widget widget-{$col_width} border-{$border_color} {$no_padding_class} {$hide_title_class}", $params[0]['before_widget'], 1 );
    		
    	}
    
    	if( $border_color == 'custom' && $custom_color ) {
    		
    		$params[0]['after_widget'] .= '<style type="text/css">';
    		$params[0]['after_widget'] .= sprintf('#%s { border-color: %s; }', $widget_id, $custom_color);
    		$params[0]['after_widget'] .= '</style>';
    		
    	}
    	
    	// return
    	return $params;
    
    }
    in reply to: Having an issue with Yoast Analytics outbound link tracking #3402
    Josh Guss
    Participant

    Hey Daron,

    Thanks! This is exactly what I needed to get this working properly. Take care.

    Josh

Viewing 2 posts - 1 through 2 (of 2 total)