Support » Theme: Astra » Override “before_title” for footer widget

  • Resolved unster

    (@unster)


    Hi,
    I am trying to override ‘before_title’ & ‘after_title’ setup of my widgets in footer. Unfortunately, no luck here.

    First of, I’ve tried a snippet from official site (https://wpastra.com/docs/change-sidebar-widget-title-heading-tag/), which I’ve placed in functions.php for my astra child theme. No luck, no change.

    Then, I’ve tried to override whole sidebar initialization thanks to github code I found. Once again, I’ve added following to functions.php in child theme:

    if ( ! function_exists( 'astra_widgets_init' ) ) {
    	function astra_widgets_init() {
    		/**
    		 * Register Footer Widgets area
    		 */
    		unregister_sidebar('advanced-footer-widget-1'); 
    
    		register_sidebar(
    			apply_filters(
    				'astra_advanced_footer_widget_1_args',
    				array(
    					'name'          => esc_html__( 'Footer Widget Area 1', 'astra' ),
    					'id'            => 'advanced-footer-widget-1',
    					'before_widget' => '<div id="%1$s" class="widget %2$s">',
    					'after_widget'  => '</div>',
    					'before_title'  => '<h6 class="widget-title">',
    					'after_title'   => '</h6>',
    				)
    			)
    		);
    
    		unregister_sidebar('advanced-footer-widget-2');
    		register_sidebar(
    			apply_filters(
    				'astra_advanced_footer_widget_2_args',
    				array(
    					'name'          => esc_html__( 'Footer Widget Area 2', 'astra' ),
    					'id'            => 'advanced-footer-widget-2',
    					'before_widget' => '<div id="%1$s" class="widget %2$s">',
    					'after_widget'  => '</div>',
    					'before_title'  => '<h6 class="widget-title">',
    					'after_title'   => '</h6>',
    				)
    			)
    		);	
    	}
    }

    (I need to update just two bottom widgets in footer).

    So.. so long, no luck. Can I count for a support here?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello @unster

    We are not sure exactly what you are trying to override in the footer widgets.

    If for the title, you can use the following filter –

    add_filter('astra_advanced_footer_widget_1_args' , 'change_footer_title');
    
    function change_footer_title(){
    	$widget_array = array(
    		'name'          => esc_html__( 'Footer Widget Area 1 customized', 'astra' ),
    		'id'            => 'advanced-footer-widget-1',
    		'before_widget' => '<div id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h2 class="widget-title">',
    		'after_title'   => '</h2>',
    	);
    	return $widget_array;		
    }

    And similarly, for the other Footer widgets by changing the number of the filter.

    I hope that helps. Let us know if you have any further queries.

    Regards,
    Suman

    Thread Starter unster

    (@unster)

    You are G-R-E-A-T. Works like charm.
    My intention was only to change H2 tag to H4.

    In order to update 3 advanced footer widgets I’ve copied the function three times. Any other way to make it more elegant?

    Perfect and glad to hear that, @unster!

    Similarly, for the other widgets as mentioned in the previous response, you will just need to create separate functions. There’s no more elegant way than that. Sorry!

    Do let us know if there’s anything else we can help you with. Also, please mark the Topic as resolved. šŸ™‚

    Regards,
    Suman

    Thread Starter unster

    (@unster)

    Now I have all the answers, thanks!

    Perfect, @unster!

    Glad to hear that. šŸ™‚

    Do let us know if there is anything else we can help you with.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Override “before_title” for footer widget’ is closed to new replies.