Archived topic
problems: menu & bbpress
18 replies · Started by Uwe Pfeifer on October 17, 2015
I have a problem. If I click "Forums" (bbpress) in the menu, the highlighted item is "Blog" not "Forums". Can you help me? Here a video:
https://youtu.be/6jW9cXzeWy8
Hi there,
This should help: https://generatepress.com/forums/topic/menu-item-forum-thinks-it-is-a-child-of-item-blog/#post-141727
I added this into functions.php but now the menu item Forum is moved to the right, and its still not working.
function generate_remove_bbpress_parent_classes($class)
{
return ( $class == 'current_page_parent' ) ? FALSE : TRUE;
}
add_filter('nav_menu_css_class', 'generate_remove_bbpress_parent_class');
function generate_remove_bbpress_parent_class($classes)
{
switch (get_post_type())
{
case 'forum':
// we're viewing a custom post type, so remove the 'current_page_parent' from all menu items.
$classes = array_filter($classes, "generate_remove_bbpress_parent_classes");
break;
}
return $classes;
}
the website is here: http://www.unityhub.eu
in the menu settings i have forum blog but it appears as blog forum and still, the wrong item is highlighted when selecting forum
the functions.php looks like this now hope i made the ?> correct at the end:
<?php
/**
* Generate child theme functions and definitions
*
* @package Generate
*/
function generate_remove_bbpress_parent_classes($class)
{
return ( $class == 'current_page_parent' ) ? FALSE : TRUE;
}
add_filter('nav_menu_css_class', 'generate_remove_bbpress_parent_class');
function generate_remove_bbpress_parent_class($classes)
{
switch (get_post_type())
{
case 'forum':
// we're viewing a custom post type, so remove the 'current_page_parent' from all menu items.
$classes = array_filter($classes, "generate_remove_bbpress_parent_classes");
break;
}
return $classes;
}
?>
wait now it's working - the blog item doesnt get highlighted anymore. but now the forum element isnt highlighted aswell when i click on forum but id like that one to get highlighted?
also if i click the forum link, in the browser title bar its not Forums | UnityHub but instead just Forums | ?
I made a change to the code to add the current menu item class to the blog while on it: https://gist.github.com/generatepress/f5e4f6d1795cf6bb4c6a
As for the title tag - that's bbPress/WordPress functionality. Your best bet is using a plugin like WordPress SEO to change the structure of the title tag for the forums post type.
i now put this code in the file, overwriting the old code:
function generate_remove_bbpress_parent_classes($class)
{
return ( $class == 'current_page_parent' ) ? FALSE : TRUE;
}
add_filter('nav_menu_css_class', 'generate_remove_bbpress_parent_class');
function generate_remove_bbpress_parent_class( $classes, $item )
{
switch (get_post_type())
{
case 'forum':
// we're viewing a custom post type, so remove the 'current_page_parent' from all menu items.
$classes = array_filter($classes, "generate_remove_bbpress_parent_classes");
if ( $item->url == get_permalink( get_option( 'page_for_posts' ) ) ) {
$classes[] = 'current_page_parent';
}
break;
}
return $classes;
}
but still the forum element is not highlighted when activated.
and about the title ... for all other menu items it works - just not for the forum one? why would a seo plugin help me there?
Just updated it again: https://gist.github.com/generatepress/f5e4f6d1795cf6bb4c6a
The WordPress SEO plugin allows you to set the structure for the title tag for custom post types. Some custom post types, bbPress included, don't display the title tag very nicely.
GP doesn't do anything to the title tag, we leave it 100% up to WordPress and plugins incorporation custom post types. bbPress just isn't developed to include nice title tags.
thank you a lot for the information.
yes i put the new code inside the functions.php but its still not working.
Hmm, I've tested it successfully.
When you go to "Settings > Forums", what do you have set as your "Forum Root"?
Forum root is "forums"
Ok, let's try this again: https://gist.github.com/generatepress/f5e4f6d1795cf6bb4c6a
That code should remove the highlight from the Blog menu item, but keep the highlight while on the main forum pages (yoursite.com/forums).
no, doesnt work. still the same. when clicking on forum, nothing is highlighted.
