Tagged: archive, breadcrumbs, category, tag
-
AuthorPosts
-
January 18, 2018 at 6:05 pm #899220
Hi,
how can I add text in the breadcrumbs please in that way:
Currently the breadcrumbs of the category & tag archive pages look like this:
You are here: Home / Blog / XYZ
It should be:
You are here: Home / Blog / Category: XYZ
XYZ is a category name; I would like to add “Category: ” before it, and at a tag archive “Tag: ”
I searched in the class-breadcrumb.php in line 338 at
/* Get the path to the term archive.
And added “Category” and “Tag” like this:
/* Get the path to the term archive. Use this to determine if a page is present with it. */ if ( is_category() ) // $path = get_option( 'category_base' ); $path = 'Category ' . get_option( 'category_base' ); elseif ( is_tag() ) // $path = get_option( 'tag_base' ); $path = 'Tag ' . get_option( 'tag_base' ); else { if ( $taxonomy->rewrite['with_front'] && $wp_rewrite->front ) $path = trailingslashit( $wp_rewrite->front ); $path .= $taxonomy->rewrite['slug']; }
But this has simply no effect, but I am not sure, if this is the right place and the right way of adding it, because my PHP is really bad.
My site is not online yet, but I use simply the normal Avia Breadcrumbs, no YOAST breadcrumbs!Thanks for helping me out.
January 22, 2018 at 5:13 am #900584Hey Chris,
I found this thread that can help you: https://kriesi.at/support/topic/adding-text-to-the-breadcrumbs-of-the-category-and-tag-archive-pages/#post-124362
Best regards,
John TorvikJanuary 22, 2018 at 11:22 am #900739Hi,
thanks, but as you can see at my code snippet above, I have already done this, see line 340 of my current class-breadcrump.php: https://pastebin.com/fBNzZ5SC
/* Get the path to the term archive. Use this to determine if a page is present with it. */ if ( is_category() ) $path = 'Thema ' . get_option( 'category_base' ); elseif ( is_tag() ) $path = 'Schlagwort ' . get_option( 'tag_base' ); else { if ( $taxonomy->rewrite['with_front'] && $wp_rewrite->front ) $path = trailingslashit( $wp_rewrite->front ); $path .= $taxonomy->rewrite['slug']; }
but in the breadcrumbs this does not appear! I use the newest version of ENFOLD & WP, and my site is not yet online!
January 25, 2018 at 4:21 am #902487Hi,
Thank you for the update.
Please remove the modification. Use the following filter in the functions.php file instead.
add_filter( 'avia_breadcrumbs_trail', 'avia_breadcrumbs_trail_mod', 50, 2 ); function avia_breadcrumbs_trail_mod( $trail, $args ) { if ( is_category() ) { $trail['trail_end'] = 'Thema: ' . $trail['trail_end']; } elseif ( is_tag() ) { $trail['trail_end'] = 'Schlagwort: ' . $trail['trail_end']; } else { $trail['trail_end'] = $trail['trail_end']; } return $trail; }
Best regards,
IsmaelFebruary 23, 2018 at 12:53 am #916446Hi Ismael,
sorry for the delay and thanks for your code snippet, but it does not work:
it shows not the word “Thema” (= Category in English) in front of the category name,
and not “Schlagwort” (= Tag in English) in front of a tag name.do you have any modifications of your code?
February 24, 2018 at 5:16 am #916966Hi,
Thank you for the update. Please replace ‘trail_end’ with 2. Example.
$trail[2] = 'Thema: ' . $trail[2];
Best regards,
IsmaelFebruary 24, 2018 at 12:32 pm #917055Thanks, but where do I need to add your new line
$trail[2] = 'Thema: ' . $trail[2];
in this snippet
add_filter( 'avia_breadcrumbs_trail', 'avia_breadcrumbs_trail_mod', 50, 2 ); function avia_breadcrumbs_trail_mod( $trail, $args ) { if ( is_category() ) { $trail['trail_end'] = 'Thema: ' . $trail['trail_end']; } elseif ( is_tag() ) { $trail['trail_end'] = 'Schlagwort: ' . $trail['trail_end']; } else { $trail['trail_end'] = $trail['trail_end']; } return $trail; }
do you mean to replace every time the word “end” with “2”?
Sorry for the stupid question, but I don’t know PHP very well :-(And how can I combine all this with the snippet from you, that I need so that it does not show “Blog” twice?
“Blog” is shown twice on category and tag archive, in single post view it is okay.thank you
February 26, 2018 at 4:46 am #917657Hi,
Thank you for the update.
Please use this filter instead. Remove the previous ones.
add_filter( 'avia_breadcrumbs_trail', 'avia_breadcrumbs_trail_mod', 50, 2 ); function avia_breadcrumbs_trail_mod( $trail, $args ) { if ( is_archive() ) { unset($trail[1]); } if ( is_category() ) { $trail[2] = 'Thema: ' . $trail[2]; } elseif ( is_tag() ) { $trail[2] = 'Schlagwort: ' . $trail[2]; } else { $trail[2] = $trail[2]; } return $trail; }
Best regards,
IsmaelFebruary 26, 2018 at 3:59 pm #917869Works fine, thank you very much.
February 27, 2018 at 5:02 am #918157Hi Gitte,
Glad Ismael could help :)
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.