Tagged: archives, breadcrumbs, categories, navigation
-
AuthorPosts
-
January 20, 2023 at 3:03 pm #1394538
Dear Kriesis,
I’m creating a website with lots of posts and different categories. I set up pages and use the Avia Blog Post element to display posts filtered by categories in different ways. This works fine and provides an indivual layout for these pages and individual sidebars.The Problem is the breadcrumb navigation. As long as I navigate the page links in the main menu everything works fine. But as soon as I visit a single post the breadcrumb navigation switches to categories what is confusing.
Styling the category archives is very limited and showing the archives is not wanted.
Is it possible to hide the breadcrumb category navigation and display the page navigation on single posts with post name at the end of trail, as e.g.:
Home / Auktionen(=page) / Premium Aktionen(=page) / Postname
instead of:
Home / Auktionen cat (=category) / Premiumauktionen cat(=category) / Postname
?
I found some php-snippets in former support topics:add_filter( ‘avia_breadcrumbs_trail’, ‘remove_category_from_breadcrumb’, 50, 2, );
function remove_category_from_breadcrumb( $trail, $args ) {
if ( is_single() ) {
unset ($trail[1]);
unset ($trail[2]);
}
return $trail;
}add_filter( ‘avia_breadcrumbs_args’, ‘avia_breadcrumbs_args_mod’, 10, 2 );
function avia_breadcrumbs_args_mod( $args ) {
// print_r($_SERVER);
// [REQUEST_URI] => /category/auktionen-cat/e-auktionen/
// print_r($args);
$urlsWithoutCatShow = array(‘/auktionen-cat/’);
foreach ($urlsWithoutCatShow as $url) {
if (strpos($_SERVER[‘REQUEST_URI’], $url) !== false) {
$args[‘show_categories’] = false;
}
}$args[‘show_categories’] = false;
return $args;
}At the moment these sripts are disabled in the functions.php in my Enfold childtheme. By enabling the categories are hide but the breadcrumb trail is too short and useless: Home / Postname
I’m looking forward to any idea.
Best regards
AnneJanuary 22, 2023 at 4:03 am #1394681Hey annevoelkel,
To remove that category from the breadcrumbs please use code to the end of your child theme functions.php file in Appearance ▸ Editor:add_filter( 'avia_breadcrumbs_trail', 'remove_category_from_breadcrumb', 50, 2, ); function remove_category_from_breadcrumb( $trail, $args ) { if ( is_single() ) { unset ($trail[2]); } return $trail; }
Without this function the breadcrumbs will show the category:
With the function the category is removed:
Best regards,
MikeJanuary 23, 2023 at 11:14 am #1394755Hello Mike,
thanks for the code. This works quite well. But it seems to be impossible to mix pages and blog posts in the breadcrumb trail like this:
Home / Auktionen(=page) / Premium Aktionen(=page) / PostnameBest regards
AnneJanuary 23, 2023 at 12:26 pm #1394766Hi,
Glad this helps, the breadcrumbs for posts are for their relationship to the blog.
Pages are shown the breadcrumbs in their relationship to their parent page.
I don’t see where you could have a mix of pages and posts.Best regards,
MikeJanuary 23, 2023 at 12:30 pm #1394767Hello Mike,
I understand and it is also logical.
Best regards
AnneJanuary 23, 2023 at 12:38 pm #1394772Hi,
Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.Best regards,
Mike -
AuthorPosts
- The topic ‘disable categories in breadcrumb navigation’ is closed to new replies.