Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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.

    #900584

    Hey 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 Torvik

    #900739

    Hi,

    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!

    #902487

    Hi,

    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,
    Ismael

    #916446

    Hi 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.

    View post on imgur.com

    do you have any modifications of your code?

    #916966

    Hi,

    Thank you for the update. Please replace ‘trail_end’ with 2. Example.

    $trail[2] = 'Thema: ' . $trail[2];
    

    Best regards,
    Ismael

    #917055

    Thanks, 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

    #917657

    Hi,

    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,
    Ismael

    #917869

    Works fine, thank you very much.

    #918157

    Hi Gitte,

    Glad Ismael could help :)

    If you need further assistance please let us know.
    Best regards,
    Victoria

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.