Tagged: navigation, sidebar
-
AuthorPosts
-
August 26, 2024 at 5:49 am #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,
JasonAugust 26, 2024 at 7:12 am #1465394Hey!
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!
IsmaelAugust 26, 2024 at 7:27 am #1465397wow – that is super cool – thank you Ismael !
August 26, 2024 at 8:34 am #1465401Hi,
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,
RikardAugust 26, 2024 at 10:14 pm #1465449just 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)
August 26, 2024 at 11:51 pm #1465452actually, 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);
August 27, 2024 at 9:12 am #1465477 -
AuthorPosts
- You must be logged in to reply to this topic.