Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do I edit bbPress breadcrumbs?

  • @dominornovus

    Member

    What I want to achieve:

    I’ve installed bbPress as a plugin for WordPress. I want to make a few simple changes to the bbPress bread crumb function:

    bbp_breadcrumb();

    I need the bread crumb separator to be double right arrows rather than the default single arrow:

    I want to replace > with ».

    I also want to add “You are here:”

    Why I need this:

    I need to match the styling and position the Yoast Breadcrumbs. Yoast Breadcrumbs is installed as a plugin for WordPress. It breaks on bbPress pages.

    What I’ve tried:

    Using conditions and CSS, I disabled the Yoast bread crumbs on bbPress pages. I also disabled the default bbPress bread crumbs but called it just beneath my primary navigation. Effectively, I’ve “moved” the bbPress bread crumbs.

    To change the bread crumb separator I’ve researched JavaScript and jQuery string replacements but I’ve been advised that this is “hacky”.

    My question:

    What’s the conventional way of changing the output of bbPress function?

    I can provide additional JavaScript, PHP and CSS code if required.

    Live demo:

    These two live examples highlights the two types of bread crumbs:

    Yoast bread crumbs: http://www.directsponsor.org/forums/

    bbPress bread crumbs: http://www.directsponsor.org/news/

Viewing 21 replies - 1 through 21 (of 21 total)
  • @dominornovus

    Member

    I have come across an example of a filter to change the bread crumb separators but I can’t seem to get it to work:

    add_filter( 'breadcrumb_trail_args', 'my_breadcrumb_trail_args' );

    function my_breadcrumb_trail_args( $args ) {

    $args = ‘ → ‘;

    return $args;

    }

    Source: http://themehybrid.com/support/topic/change-separator-breadcrumb#post-22852

    @dominornovus

    Member

    I’ve found a list of hooks and filters for bbPress at:

    /wp-content/plugins/bbpress/bbp-includes/bbp-core-hooks.php

    I’ve also found the bbPress bread crumb function(s) at:

    /wp-content/plugins/bbpress/bbp-includes/bbp-common-template.php

    By combining code from the two, I’ve attempted adding a filter but it’s being ignored:

    function test_args($args) {

    $args = array(

    'sep' => ' x ',

    );

    return $args;

    }

    add_filter('bbp_title','test_args');

    @dominornovus

    Member

    In bbp-common-template.php I found:

    // Allow the separator of the breadcrumb to be easily changed

    $sep = apply_filters( 'bbp_breadcrumb_separator', $sep );

    I attempted to apply a filter…

    $sep = 'x';

    add_filter('bbp_breadcrumb_separator', $sep);

    …but it resulted in:

    Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'x' was given in

    @dominornovus

    Member

    I’ve figured out how to change the bread crumb separator:

    <br /><br />
    // Change bbPress bread crumb separator.
    function filter_bbPress_breadcrumb_separator() {
    //$sep = ' &raquo; ';
    $sep = is_rtl() ? __( ' &laquo; ', 'bbpress' ) : __( ' &raquo; ', 'bbpress' );
    return $sep;
    }
    
    add_filter('bbp_breadcrumb_separator', 'filter_bbPress_breadcrumb_separator');

    I have not yet figured out how to add “You are here: ” at the start of the bread crumbs:

    I’ve tried this…

    <br /><br />
    function my_breadcrumb_trail_args( $trail ) {<br /><br />
    $args = '<div class="bbp-breadcrumb"><p>You are here: ';<br /><br />
    return $args;<br /><br />
    };<br /><br />
    add_filter( 'breadcrumb_trail_args', 'my_breadcrumb_trail_args' );<br /><br />
    

    …and this…

    <br /><br />
    function test($defaults) {<br /><br />
    $defaults = array(<br /><br />
    'before' => '<div class="bbp-breadcrumb"><p>You are here: ',<br /><br />
    );<br /><br />
    return $defaults;<br /><br />
    }<br /><br />
    add_filter('bbp_breadcrumb','test_args');<br /><br />
    

    Neither work.

    For now I’ve taken the hacky approach and just edited my bbPress files directly. You can see it in action here: http://www.directsponsor.org/forums/

    Any assistance with the filter would be greatly appreciated.

    @mattsimo

    Member

    I made a filter that set’s the before, after, sep & root_text for the breadcrumbs. Take a look, writes over the ‘bbp_get_breadcrumb_pre’ filter found on line 1553 of bbp-includes/bbp-common-template.php

    // Change bbPress bread crumb separator.
    function filter_bbp_breadcrumb( $args ) {

    $my_args = array(
    'before' => "n<div class="subnav bbp-breadcrumb ">n <ul class="nav nav-pills ">n <li>",
    'after' => "</li>n </ul>n</div>nn",
    'sep' => is_rtl() ? __( "</li>n <li>", 'bbpress' ) : __( "</li>n <li>", 'bbpress' ),
    'root_text' => "Support"
    );

    $args = wp_parse_args( $my_args, $args );
    return $args;

    }
    add_filter('bbp_get_breadcrumb_pre', 'filter_bbp_breadcrumb' );

    @jaredatch

    Member

    Yep thats correct. You can pick and choose the args if you don’t want to reset all of them.

    function custom_forum_breadcrumb( $args ) {

    $args['sep'] = ' | ';

    return $args;

    }
    add_filter( 'bbp_get_breadcrumb_pre', 'custom_forum_breadcrumb' );

    @kennymcnett

    Member

    Thanks mattsimo and jaredatch. Worked the charm.

    Here are all of the $args and the defaults, FYI (pulled from bbPress core file: bbp-common-template.php)

    // HTML
    'before' => '<div class="bbp-breadcrumb"><p>',
    'after' => '</p></div>',
    'sep' => is_rtl() ? __( '&lsaquo;', 'bbpress' ) : __( '&rsaquo;', 'bbpress' ),
    'pad_sep' => 1,

    // 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

    @manuelmasia

    Member

    Hi everyone…

    since BBPress 2.1 has removed bbp_get_breadcrumb_pre filter, can anyone provide a quick solution to get the same result as above?

    Thanks

    @manuelmasia

    Member

    Ok, at the moment I tested this


    function custom_bbp_breadcrumb($r) {
    $r = ' | ';
    return $r;
    }
    add_filter('bbp_before_get_breadcrumb_parse_args', 'custom_bbp_breadcrumb' );

    and it seems to work, but maybe there is a more elegant solution… any help is appreciated :-)

    @clayheaton

    Member

    Where does one install filters in 2.1?

    @lynq

    Participant

    Because bbPress is just a plugin you should be able to put filters into your functions.php file of your wordpress theme.

    @clayheaton

    Member

    So, using the code example several posts above, from manuelmasia — let’s say that I wrap that in php tags and drop it into a functions.php file in my child theme directory. Is there anything else that I would need to do in order to get the breadcrumbs to display differently?

    • This reply was modified 12 years, 5 months ago by Clay.

    @lynq

    Participant

    It should work, I am not sure if you will need to wrap it in php tags though?
    I don’t need to in my functions file.

    @lynq

    Participant

    By the way this code snippet works for me:

    function custom_bbp_breadcrumb() {
        $args['sep'] = ' | ';
        return $args;
    }
    
    add_filter('bbp_before_get_breadcrumb_parse_args', 'custom_bbp_breadcrumb' );
    
    • This reply was modified 12 years, 5 months ago by Lynq.

    @clementtang

    Member

    Open bbp-common-template.php from bbp-include
    find

    // Wrap the separator in a span before padding and filter if ( !empty( $sep ) )
    

    and edit

    $sep = '' . ' EDIT HERE ' . '';
    

    You can change it into any text or image w/ codes.

    • This reply was modified 12 years, 4 months ago by Clementtang.
    • This reply was modified 12 years, 4 months ago by Clementtang.

    @johnjamesjacoby

    Keymaster

    Don’t modify bbPress core. Use the filters instead.

    @daveshine

    Participant

    I’ve released a small bbPress Plugin called “String Swap” where you can easily change a few breadcrumb parameters as well as some other strings for the frontend.

    You can check it out here:
    https://wordpress.org/extend/plugins/bbpress-string-swap/

    After installing/activating, look on the bbPress Settings page where there is a new section then 🙂

    Hope this helps some users 🙂
    -Dave.

    @macpresss

    Participant

    @JJJ

    Please do the people on bbPress.org a huge favor and delete all the fancy stuff in this comment-form, just load the default wordpress.ORG comment-form it’s huge and only support a few needed options. This is getting ridicules. People have to be an acrobat to post some code on this forums.

    I can’t copy-/paste @mattsimo code because of this forum-software.

    Safari + Firefox it doesn’t copy the the selected code i needed.

    @tjtate

    Participant

    updated list as of 2.2:

     

    $defaults = array(

     

    // HTML

    ‘before’          => ‘<div class=”bbp-breadcrumb”><p>’,

    ‘after’           => ‘</p></div>’,

     

    // Separator

    ‘sep’             => __( ‘&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>’,

    );

    pulled from bbpress/includes/common/template-tags.php

     

    setup your args and pass them to the bbp_breadcrumb function 

    @kristinachilds

    Participant

    How do you change just the defaults in this new version? Every time I try, the only output is “Array”. I don’t want to filter the whole function, just the

    ‘before’ => ”,
    ‘after’ => ”,

    @kristinachilds

    Participant

    Nevermind, Lynq’s solution worked the 2nd time I tried it.

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