Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1465389

    hey there,
    so i’m aware that if “Page Sidebar Navigation” is on in theme options then this is automatically generated.
    i have one particular clients whose site has become enormous and is frequently asking me to hide some of the links in the sidebar.
    i’ve been doing this using css, not the most elegant solution – but it works.
    however, (i think i already know the answer to this question, but need to ask regardless) said client now wants to manually add in a link to this menu in the sidebar.
    this isn’t simple – is it.
    any advice?
    thanks,
    Jason

    #1465394

    Hey!

    Thank you for the inquiry.

    You can use the avf_sidebar_menu_filter filter to adjust the output of the page sidebar navigation. The following example shows how to append a custom menu item at the very end of the list:

    function append_custom_menu_item($sidebar_menu, $args, $post) {
        $custom_menu_item = '<li class="page_item"><a href="your-custom-url">Your Custom Menu Item</a></li>';
        $sidebar_menu = str_replace('</ul>', $custom_menu_item . '</ul>', $sidebar_menu);
    
        return $sidebar_menu;
    }
    
    add_filter('avf_sidebar_menu_filter', 'append_custom_menu_item', 10, 3);
    

    Cheers!
    Ismael

    #1465397

    wow – that is super cool – thank you Ismael !

    #1465401

    Hi,

    Great, I’m glad that Ismael could help you out. Please let us know if you should need any further help on the topic, or if we can close it.

    Best regards,
    Rikard

    #1465449

    just one last question related to this, is it possible to add this to just a specific parent, e.g. all sub pages of /africa (for example)

    #1465452

    actually, i think i have the solution

    function append_custom_menu_item($sidebar_menu, $args, $post) {
        // Check if the current page is either '/africa' or a subpage of '/africa'
        $is_africa_page = ($post->post_name === 'africa');
        $is_africa_subpage = ($post->post_parent && get_post($post->post_parent)->post_name === 'africa');
    
        if ($is_africa_page || $is_africa_subpage) {
            $custom_menu_item = '<li class="page_item"><a href="your-custom-url">Your Custom Menu Item</a></li>';
            $sidebar_menu = str_replace('</ul>', $custom_menu_item . '</ul>', $sidebar_menu);
        }
    
        return $sidebar_menu;
    }
    
    add_filter('avf_sidebar_menu_filter', 'append_custom_menu_item', 10, 3);
    #1465477

    Hi,

    Great, I’m glad that you found a solution and thanks for sharing.

    Best regards,
    Rikard

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.