Tagged: breadcrumbs
-
AuthorPosts
-
July 8, 2024 at 10:29 am #1461600
Hi
I have an issue with the breadcrumb in the header. In the news section of the site there is an extra step in the breadcrumb that should NOT be there.
When you access the news section, the breadcrumb reads Home/News, but when you click on the article the breadcrumb reads Home/News/News/name of article. The second news should not be there.When you acces the archive on the right side and click on moth year you get Home/News/Automatic draft/Year/Month. If you click on automatc draft you got to a 404 page, and if you click on one of the articles for that month we are back to Home/News/News/Name of article.
How do I get rid of the second step and how is it even there?
Regards
NinaJuly 10, 2024 at 7:58 am #1461749Hey Advantage09,
Thank you for the inquiry.
Did you create a category named “News”? It’s possible that both the page “News” and the category “News” are being included in the breadcrumb. If that’s not the case, you can add this filter to your functions.php file to remove the duplicate entry.
function avia_breadcrumbs_trail_mod($trail) { // remove news trail if ( is_singular( 'post' ) ) { unset($trail[1]); } return $trail; } add_filter('avia_breadcrumbs_trail', 'avia_breadcrumbs_trail_mod', 50, 1);
Best regards,
IsmaelJuly 11, 2024 at 8:34 am #1461830Hi
Yes, there is a category named nyheter (news), but there is no category named Automatic draft so I am not sure thats it.
Trying your script removes the extra news and/or Automatic draft in the breadcrumb trail. BUT, when accessing the archive section on the right side and click on any random month year link you see the home/news/year/month but when clicking on the article itself the year and month dissapears. So clicking backwards in the breadcrumb trail is not possible. You have to start over again in the archive menu.
Is there a way to keep the entire breadcrumb?Regards
NinaJuly 12, 2024 at 7:28 am #1461898Hi,
Thank you for the update.
In the single post page, the default breadcrumb structure is: Home > Blog Page > First Category > Post, which is why you’re seeing the “News” category in the breadcrumb. If you want to remove the category and include the archive date instead, you can use the following code in place of the previous filter:
function avia_breadcrumbs_trail_mod($trail) { global $post; if ( is_singular( 'post' ) ) { $end = $trail['trail_end']; unset($trail['trail_end']); unset($trail[2]); $post_month = get_the_date('F Y', $post); $trail[] = '<a href="' . get_month_link(get_post_time('Y'), get_post_time('m')) . '" title="' . esc_attr($post_month) . '" rel="">' . $post_month . '</a>'; $post_year = get_the_date('Y', $post); $trail[] = '<a href="' . get_year_link($post_year) . '" title="' . esc_attr($post_year) . '" rel="">' . $post_year . '</a>'; $trail[] = $end; } return $trail; } add_filter('avia_breadcrumbs_trail', 'avia_breadcrumbs_trail_mod', 50, 1);
Best regards,
IsmaelJuly 15, 2024 at 11:05 am #1462074This is somewhat ok. Not perfect, but I can live with it for now.
Thanks
Regards
NinaJuly 15, 2024 at 1:37 pm #1462088 -
AuthorPosts
- The topic ‘Breadcrumbs’ is closed to new replies.