Skip to:
Content
Pages
Categories
Search
Top
Bottom

Change Breadcrumb url link

Viewing 23 replies - 26 through 48 (of 48 total)

  • Robin W
    Moderator

    @robin-w

    sorry end of a long day, and brain is frying after several hours coding, so apologies.

    can you show your current breadcrumb, and what it links to, and the desired breadcrumb and what you would like it to link to


    se7en1216
    Participant

    @se7en1216

    Robin
    Here the the actual forum page that I want as the main page. If you hover over any of the breadcrumbs, you’ll see they read /forums-root/. I would like to replace that with /forums/

    I hide the breadcrumbs by css on this page usually, but I’m showing them now so you can see it all on one page.

    http://forgebreaker.net/forums/


    Robin W
    Moderator

    @robin-w

    it should be :

    Dashboard>settings>forums>forum root slug and set to forums


    se7en1216
    Participant

    @se7en1216

    If I change the page as you mentioned, all shortcodes for the http://forgebreaker.net/forums/ page are overwritten, and you end up with several copies of the forum-index shortcode instead.


    Robin W
    Moderator

    @robin-w

    I’m sorry but I don’t understand what you mean.

    What shortcodes – where?

    You will need to either provide examples or explain further.

    Sorry, but I am trying to help you, but there are hundreds of ways to set up wordpress/bbpress so need clear issues to resolve eg it looks like this, it needs to look like this


    se7en1216
    Participant

    @se7en1216

    This page is currently written as just a simple WordPress page with several shortcodes as listed below:

    General Discussions
    
    [bbp-single-forum id=3926]
    
    Guild Discussions
    
    [bbp-single-forum id=3924]
    
    Group Forums
    
    [bbp-single-forum id=10169]

    When changing the Settings to have /forums as the forum root page, it changes all of the above listed shortcodes visually to look like it was just duplicated over and over from the current /forums-root page. It loses all of the current forum IDs and they all turn into a general forum-index.

    This is why I can’t just swap it in the Setting menu for the forums, and the reason I want the current Forum breadcrumb to direct to /forums and not /forums-root.

    If you would like, take a look at the way it looks now, and I’ll switch it after so you can see what it is doing.


    se7en1216
    Participant

    @se7en1216

    To clarify: I just need to know how I can change the Forums breadcrumb link to go to the /forums page and not /forums-root without changing it through Settings>Forums>Forum Root Slug.


    se7en1216
    Participant

    @se7en1216

    So earlier, someone suggested doing the following:

    // Add the breadcrumb
    // $crumbs[] = '<a href="' . esc_url( $root_url ) . '">' . $r['root_text'] . '</a>';
    $crumbs[] = '<a href="/forum/">Forum</a>';

    Can I make a duplicate of the template.php to drop into my theme somewhere to make a similar change? This works, but I don’t like the idea of altering the main bbpress files.


    Robin W
    Moderator

    @robin-w

    Just had a look at your site, and you seem to have ‘fixed’ this – correct, and if so how did you do it?

    If by altering core file, let me know, and I’ll give you a better solution.


    se7en1216
    Participant

    @se7en1216

    Hey Robin, yes, I altered the core for now until another solution was provided. Any help you could provide would be very much welcomed! 🙂


    Robin W
    Moderator

    @robin-w

    ok, can you post the lines you altered and which file eg

    fileaa.php lines 47-50

    altered from

    xxx
    xxx
    xxx

    to

    yyy
    yyy
    yyy

    Thanks


    se7en1216
    Participant

    @se7en1216

    Sorry for the delay, was out yesterday evening.

    I altered the template.php file and put the following at line 2266

    Original:

    // Add the breadcrumb
    // $crumbs[] = '<a href="' . esc_url( $root_url ) . '">' . $r['root_text'] . '</a>';

    Modified:

    // Add the breadcrumb
    // $crumbs[] = '<a href="' . esc_url( $root_url ) . '">' . $r['root_text'] . '</a>';
    $crumbs[] = '<a href="/forums/">Forums</a>';
    }

    Robin W
    Moderator

    @robin-w

    ok, I’ve had a detailed look, and there is no simple filter, so we just copy the function, rename it, and the hook back

    so post this in your functions file

    function change_root( $args = array() ) {
    
    		// Turn off breadcrumbs
    		if ( apply_filters( 'bbp_no_breadcrumb', is_front_page() ) )
    			return;
    
    		// Define variables
    		$front_id         = $root_id                                 = 0;
    		$ancestors        = $crumbs           = $tag_data            = array();
    		$pre_root_text    = $pre_front_text   = $pre_current_text    = '';
    		$pre_include_root = $pre_include_home = $pre_include_current = true;
    
    		/** Home Text *********************************************************/
    
    		// No custom home text
    		if ( empty( $args['home_text'] ) ) {
    
    			$front_id = get_option( 'page_on_front' );
    
    			// Set home text to page title
    			if ( !empty( $front_id ) ) {
    				$pre_front_text = get_the_title( $front_id );
    
    			// Default to 'Home'
    			} else {
    				$pre_front_text = __( 'Home', 'bbpress' );
    			}
    		}
    
    		/** Root Text *********************************************************/
    
    		// No custom root text
    		if ( empty( $args['root_text'] ) ) {
    			$page = bbp_get_page_by_path( bbp_get_root_slug() );
    			if ( !empty( $page ) ) {
    				$root_id = $page->ID;
    			}
    			$pre_root_text = bbp_get_forum_archive_title();
    		}
    
    		/** Includes **********************************************************/
    
    		// Root slug is also the front page
    		if ( !empty( $front_id ) && ( $front_id === $root_id ) ) {
    			$pre_include_root = false;
    		}
    
    		// Don't show root if viewing forum archive
    		if ( bbp_is_forum_archive() ) {
    			$pre_include_root = false;
    		}
    
    		// Don't show root if viewing page in place of forum archive
    		if ( !empty( $root_id ) && ( ( is_single() || is_page() ) && ( $root_id === get_the_ID() ) ) ) {
    			$pre_include_root = false;
    		}
    
    		/** Current Text ******************************************************/
    
    		// Search page
    		if ( bbp_is_search() ) {
    			$pre_current_text = bbp_get_search_title();
    
    		// Forum archive
    		} elseif ( bbp_is_forum_archive() ) {
    			$pre_current_text = bbp_get_forum_archive_title();
    
    		// Topic archive
    		} elseif ( bbp_is_topic_archive() ) {
    			$pre_current_text = bbp_get_topic_archive_title();
    
    		// View
    		} elseif ( bbp_is_single_view() ) {
    			$pre_current_text = bbp_get_view_title();
    
    		// Single Forum
    		} elseif ( bbp_is_single_forum() ) {
    			$pre_current_text = bbp_get_forum_title();
    
    		// Single Topic
    		} elseif ( bbp_is_single_topic() ) {
    			$pre_current_text = bbp_get_topic_title();
    
    		// Single Topic
    		} elseif ( bbp_is_single_reply() ) {
    			$pre_current_text = bbp_get_reply_title();
    
    		// Topic Tag (or theme compat topic tag)
    		} elseif ( bbp_is_topic_tag() || ( get_query_var( 'bbp_topic_tag' ) && !bbp_is_topic_tag_edit() ) ) {
    
    			// Always include the tag name
    			$tag_data[] = bbp_get_topic_tag_name();
    
    			// If capable, include a link to edit the tag
    			if ( current_user_can( 'manage_topic_tags' ) ) {
    				$tag_data[] = '<a href="' . esc_url( bbp_get_topic_tag_edit_link() ) . '" class="bbp-edit-topic-tag-link">' . esc_html__( '(Edit)', 'bbpress' ) . '</a>';
    			}
    
    			// Implode the results of the tag data
    			$pre_current_text = sprintf( __( 'Topic Tag: %s', 'bbpress' ), implode( ' ', $tag_data ) );
    
    		// Edit Topic Tag
    		} elseif ( bbp_is_topic_tag_edit() ) {
    			$pre_current_text = __( 'Edit', 'bbpress' );
    
    		// Single
    		} else {
    			$pre_current_text = get_the_title();
    		}
    
    		/** Parse Args ********************************************************/
    
    		// Parse args
    		$r = bbp_parse_args( $args, array(
    
    			// HTML
    			'before'          => '<div class="bbp-breadcrumb"><p>',
    			'after'           => '</p></div>',
    
    			// Separator
    			'sep'             => is_rtl() ? __( '&lsaquo;', 'bbpress' ) : __( '&rsaquo;', 'bbpress' ),
    			'pad_sep'         => 1,
    			'sep_before'      => '<span class="bbp-breadcrumb-sep">',
    			'sep_after'       => '</span>',
    
    			// Crumbs
    			'crumb_before'    => '',
    			'crumb_after'     => '',
    
    			// Home
    			'include_home'    => $pre_include_home,
    			'home_text'       => $pre_front_text,
    
    			// Forum root
    			'include_root'    => $pre_include_root,
    			'root_text'       => $pre_root_text,
    
    			// Current
    			'include_current' => $pre_include_current,
    			'current_text'    => $pre_current_text,
    			'current_before'  => '<span class="bbp-breadcrumb-current">',
    			'current_after'   => '</span>',
    		), 'get_breadcrumb' );
    
    		/** Ancestors *********************************************************/
    
    		// Get post ancestors
    		if ( is_singular() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit() ) {
    			$ancestors = array_reverse( (array) get_post_ancestors( get_the_ID() ) );
    		}
    
    		// Do we want to include a link to home?
    		if ( !empty( $r['include_home'] ) || empty( $r['home_text'] ) ) {
    			$crumbs[] = '<a href="' . trailingslashit( home_url() ) . '" class="bbp-breadcrumb-home">' . $r['home_text'] . '</a>';
    		}
    
    		// Do we want to include a link to the forum root?
    		if ( !empty( $r['include_root'] ) || empty( $r['root_text'] ) ) {
    
    			// Page exists at root slug path, so use its permalink
    			$page = bbp_get_page_by_path( bbp_get_root_slug() );
    			if ( !empty( $page ) ) {
    				$root_url = get_permalink( $page->ID );
    
    			// Use the root slug
    			} else {
    				$root_url = get_post_type_archive_link( bbp_get_forum_post_type() );
    			}
    
    			// Add the breadcrumb
    			//$crumbs[] = '<a href="' . esc_url( $root_url ) . '" class="bbp-breadcrumb-root">' . $r['root_text'] . '</a>';
    		$crumbs[] = '<a href="/forums/">Forums</a>';
    
    		}
    
    		// Ancestors exist
    		if ( !empty( $ancestors ) ) {
    
    			// Loop through parents
    			foreach ( (array) $ancestors as $parent_id ) {
    
    				// Parents
    				$parent = get_post( $parent_id );
    
    				// Skip parent if empty or error
    				if ( empty( $parent ) || is_wp_error( $parent ) )
    					continue;
    
    				// Switch through post_type to ensure correct filters are applied
    				switch ( $parent->post_type ) {
    
    					// Forum
    					case bbp_get_forum_post_type() :
    						$crumbs[] = '<a href="' . esc_url( bbp_get_forum_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title( $parent->ID ) . '</a>';
    						break;
    
    					// Topic
    					case bbp_get_topic_post_type() :
    						$crumbs[] = '<a href="' . esc_url( bbp_get_topic_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title( $parent->ID ) . '</a>';
    						break;
    
    					// Reply (Note: not in most themes)
    					case bbp_get_reply_post_type() :
    						$crumbs[] = '<a href="' . esc_url( bbp_get_reply_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title( $parent->ID ) . '</a>';
    						break;
    
    					// WordPress Post/Page/Other
    					default :
    						$crumbs[] = '<a href="' . esc_url( get_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-item">' . get_the_title( $parent->ID ) . '</a>';
    						break;
    				}
    			}
    
    		// Edit topic tag
    		} elseif ( bbp_is_topic_tag_edit() ) {
    			$crumbs[] = '<a href="' . esc_url( get_term_link( bbp_get_topic_tag_id(), bbp_get_topic_tag_tax_id() ) ) . '" class="bbp-breadcrumb-topic-tag">' . sprintf( __( 'Topic Tag: %s', 'bbpress' ), bbp_get_topic_tag_name() ) . '</a>';
    
    		// Search
    		} elseif ( bbp_is_search() && bbp_get_search_terms() ) {
    			$crumbs[] = '<a href="' . esc_url( bbp_get_search_url() ) . '" class="bbp-breadcrumb-search">' . esc_html__( 'Search', 'bbpress' ) . '</a>';
    		}
    
    		/** Current ***********************************************************/
    
    		// Add current page to breadcrumb
    		if ( !empty( $r['include_current'] ) || empty( $r['current_text'] ) ) {
    			$crumbs[] = $r['current_before'] . $r['current_text'] . $r['current_after'];
    		}
    
    		/** Separator *********************************************************/
    
    		// Wrap the separator in before/after before padding and filter
    		if ( ! empty( $r['sep'] ) ) {
    			$sep = $r['sep_before'] . $r['sep'] . $r['sep_after'];
    		}
    
    		// Pad the separator
    		if ( !empty( $r['pad_sep'] ) ) {
    			if ( function_exists( 'mb_strlen' ) ) {
    				$sep = str_pad( $sep, mb_strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH );
    			} else {
    				$sep = str_pad( $sep, strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH );
    			}
    		}
    
    		/** Finish Up *********************************************************/
    
    		// Filter the separator and breadcrumb
    		$sep    = apply_filters( 'bbp_breadcrumb_separator', $sep    );
    		$crumbs = apply_filters( 'bbp_breadcrumbs',          $crumbs );
    
    		// Build the trail
    		$trail  = !empty( $crumbs ) ? ( $r['before'] . $r['crumb_before'] . implode( $sep . $r['crumb_after'] . $r['crumb_before'] , $crumbs ) . $r['crumb_after'] . $r['after'] ) : '';
    
    		return apply_filters( 'change_root', $trail, $crumbs, $r );
    	}
    
    add_filter ('bbp_get_breadcrumb', 'change_root') ;
    
    

    se7en1216
    Participant

    @se7en1216

    Awesome, you are a life saver Robin. So glad I could put the template file back to the original.


    Robin W
    Moderator

    @robin-w

    no problem, glad you’re fixed !


    Adri Oosterwijk
    Participant

    @adri-oosterwijk

    Although this is an old thread I just try my luck.
    The solution above does work however I’m trying to get it to work in a multi-lingual site using WPML. I know there are issues with the compatibility between bbPress and WPML. What happening is that when I click on the (altered) breadcrumb it alway returns to the English version.

    I’ve been working on a solution to use bbPress in my multi-lingual site for quite a while now and this is the one issue left.

    I do not translate the forums because I want the English topics displayed on all different language pages. However I want to achieve that the visitor is returning to /nl/supportforum/ (when the site is in Dutch) instead of /supportforum which is the English version.

    Please advice.

    Adri


    Robin W
    Moderator

    @robin-w

    If you made different versions of this function, you could test which url you are on and do the appropriate one?

    eg

    function change_root_english ( $args = array() ) {..the code in here with English words....}
    
    function change_root_danish ( $args = array() ) {..the code in here with Danish words....}
    

    then

    if [site is English one]  {
    add_filter ('bbp_get_breadcrumb', 'change_root_english') ;
    }
    if [site is Danish one] {
    add_filter ('bbp_get_breadcrumb', 'change_root_danish') ;
    }
    

    I’m sure some googling would produce a test for which site you are on to go in the [].

    @robin-w : Dutch, not Danish 🙂

    @adri-oosterwijk : Goedemorgen. I have been looking for you on the Dutch slack but didn’t find you. I have myself a WPML instance with 3 languages and I will have to think of this myself soon, so keep monitoring this thread as I might come back to you with possibilities in the next weeks.

    Pascal.


    Adri Oosterwijk
    Participant

    @adri-oosterwijk

    @robin-w: thank you for your reply. I’m sure it could work. However using this solution forces me to create a function for every language I add.

    @casiepa: Goeiemorgen, daar zijn we weer! Thanks for helping out. I have achieved a lot of what I want but the breadcrumbs remains. (for reference, see this topic on WPML: https://wpml.org/forums/topic/multiple-site-languages-but-just-a-bbpress-forum-in-english/).

    As a result of this thread I have an English forum AND a Dutch page displaying the forum with a shortcode with only one set of topics. Exactly what I want.

    For the breadcrumbs I tried to create a solution with an onclick event and then navigate back in the history but that is not reliable. When a user is entering a topic from, let’s say a google search result page and then clicking the breadcrumb link they are send back to the google page.

    I imagine something like this:

    The English page for the forum has the slug: supportforum (for example)
    The Dutch page for the forum has the slug: helpforum (for example)

    On the forum index page no breadcrumbs are needed.
    On the topics page I only want a link back to the forum index for the appropriate language.
    So the ‘solution’ must not link back to the forum slug but to the page where the index lives.
    I have absolutely no idea how to achieve this.

    The outputted link has to be something like this:

    http://www.my-site.com/forumpage-slug/

    For the other languages:
    http://www.my-site.com/language-code/localized-forumpage-slug

    In my case English is the default language and Dutch is the translation.
    The urls should be:

    http://www.my-site.com/supportforum/ -> for the default English language.
    and
    http://www.my-site.com/nl/helpforum -> for the Dutch language forum page.
    and
    same way for every other language added.

    I hope this description make sense.

    HTH

    Regards,

    Adri


    Adri Oosterwijk
    Participant

    @adri-oosterwijk

    Hi all,
    I think I got it worked out together with Otto and Tia over at WPML.
    You can have a look at it at those two topics:

    https://wpml.org/forums/topic/multiple-site-languages-but-just-a-bbpress-forum-in-english/
    https://wpml.org/forums/topic/bbpress-breadcrumbs-how-to-localize-and-point-to-the-right-page/

    BTW I hide the language switcher(s) on the topics pages by adding this piece of code in my header file

    <?php if (!is_bbpress()) {
    do_action('icl_language_selector'); 
    } ?>

    and this in my footer.php

    <?php if (!is_bbpress()) {
    do_action(‘wpml_footer_language_selector’);
    } ?>

    I hope it helps you as well.

    Regards,

    Adri

    Adri, great thing !
    Thanks for the research and posting back here.

    Pascal.

    PekMez your solution does work, but still modifying the core code will be overwritten on the upcoming update, and we will probably forget about this in the future. So after upgrade our BBPress version we forget to re-modify this code.

    Anyway how about now, is there a solution for BreadCrumbs without modifying the core?

    Aw I didn’t know this thread has two pages to which I didn’t see the Robin W amazing solution. Yes thanks man your solution works like a charm without me needing to modify the core. Cheers !

Viewing 23 replies - 26 through 48 (of 48 total)
  • You must be logged in to reply to this topic.
Skip to toolbar