Add monthly archives menu and submenu

And this is the custom code I put in my “functions.php” of my child theme.
It is important to notice that there are many things to get improved (like creating an id for every submenu and grab the classes dinamically in case you change the theme) but this was a “quick and dirty” solution. If I have ever time to improve it, I will post it. So here is the code:

function create_archives_menu_entry( $item_output="", $item = '', $depth="", $args="" ) {
    global $post;

    if ( $item->type == 'custom' && $item->object == 'custom' && $item->attr_title == 'archives') {
    //We eliminate the title since we use it just for selecting the correct entry
    $item_output = str_replace('title="archives" ' , '', $item_output);
        $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
        $indent_sub = ( $depth ) ? str_repeat( "\t", $depth + 1 ) : '';
        $item_output .= "\r\n$indent<ul class=\"sub-menu\">\r\n";
        $item_output .= wp_get_archives( array( 'type' => 'monthly', 'format' => 'custom', 'before' => $indent_sub . '<li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2407 fusion-dropdown-submenu">', 'after' => '</li>', 'echo' => 0 ) );
        $item_output .= $indent . "</ul>\r\n";
    }

    return $item_output;
}

add_filter( 'walker_nav_menu_start_el', 'create_archives_menu_entry', 10, 4 );

To make it work, you just need to add a custom link to your menu with the title attribute: archives.

And here is the working version

PS:Here is the documentation that I used to find my solution: wp_get_archives