• seanfilidis

    (@seanfilidis)


    I have a Custom Menu widget in one of my sidebars. It appears on the front page of my site. It is the third box, titled “Onderwerpen.”

    https://www.paulienzeemanlens.com/

    I would like to add HTML into this widget, but I cannot for the life of me figure out how. For example, I would like to add a picture into the widget, or a link that is not part of the menu itself. There doesn’t seem to be template files for widgets…

    Any help would be appreciated.

    Sean

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    There are no template files for widgets. Do you want the html in the menu itself or underneath it? Maybe just hardcode in the template itself.

    Thread Starter seanfilidis

    (@seanfilidis)

    I want it in the menu itself (within the generated <aside> tags).

    But all that I see in the template is <?php dynamic_sidebar( ‘sidebar-3’ ); ?>. So there is nowhere to insert code.

    Moderator keesiemeijer

    (@keesiemeijer)

    There is no easy way to do this.
    How does your theme register sidebars. Look for something similar to this in your theme’s functions.php file:

    register_sidebar( array(
    			'name' => __( 'Main Sidebar', 'twentytwelve' ),
    			'id' => 'sidebar-1',
    			'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ),
    			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    			'after_widget' => '</aside>',
    			'before_title' => '<h3 class="widget-title">',
    			'after_title' => '</h3>',
    		) );

    Thread Starter seanfilidis

    (@seanfilidis)

    This is my custom sidebar in my child functions.php

    <?php
    
    function twentythirteenchild_widgets_init() {
    
    	register_sidebar( array(
    		'name'          => __( 'Third Widget Area', 'twentythirteen' ),
    		'id'            => 'sidebar-3',
    		'description'   => __( 'Is only for the front page.', 'twentythirteen' ),
    		'before_widget' => '<aside id="%1$s" class="widget widget-fp1">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h3 class="widget-title">',
    		'after_title'   => '</h3>',
    	) );
    }
    
    add_action( 'widgets_init', 'twentythirteenchild_widgets_init' );
    
    ?>

    Wow… I could just us the after_widget attribute. Oh, no that would add it to every widget, I only want to edit that particular one.

    Moderator keesiemeijer

    (@keesiemeijer)

    By putting this in your theme’s functions.php you can add it after all nav menu widgets:

    add_filter('dynamic_sidebar_params', 'add_classes_to__widget');
    function add_classes_to__widget($params){
    
        if (substr($params[0]['widget_id'], 0, 8) == "nav_menu"){ //make sure its a nav menu
    
            $params[0]['after_widget'] .= '<h1>My html here</h1></aside>';
        }
        return $params;
    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Editing an existing widget.’ is closed to new replies.