Forums

Join
bbPress Support ForumsPluginsCustomize Topic Labels

Info

Customize Topic Labels

  1. In bb-includes/formatting-functions.php the values of the closed and sticky labels are hard coded:

    function bb_closed_label( $label ) {
            global $topic;
            if ( '0' === $topic->topic_open )
                    return sprintf(__('[closed] %s'), $label);
            return $label;
    }

    I want to change 'closed' to 'Read Only'. I know I can just hack the file, but there should be a way to use theme functions and I'm just not thawed out enough to think of it.

  2. You don't have to hack anything, it's done via a filter.

    ie.

    add_filter('bb_topic_labels', 'bb_closed_label', 10);
    add_filter('bb_topic_labels', 'bb_sticky_label', 20);


    simply remove the filter via a plugin and replace it with your own routine.

    remove_filter('bb_topic_labels', 'bb_closed_label');
    add_filter('bb_topic_labels', 'my_closed_label');
    function my_closed_label( $label ) {
            global $topic;
            if ( '0' === $topic->topic_open )
                    return sprintf(__('[Read Only] %s'), $label);
            return $label;
    }
  3. Doy!

    I put that in functions.php in my theme and it works. Thanks!

    I need to thaw my brain out.

  4. Okay, now it's weird. It works perfect for bb_closed_label, but remove_filter('bb_topic_labels', 'bb_sticky_label'); does nothing.

    What I tried was

    remove_filter('bb_topic_labels', 'bb_sticky_label');
    function my_sticky_label( $label ) {
            global $topic;
            if (is_front()) {
                    if ( '2' === $topic->topic_sticky ) {
                            return sprintf(__('<img src="/images/sticky.png" /> %s'), $label);
                    }
            } else {
                    if ( '1' === $topic->topic_sticky || '2' === $topic->topic_sticky ) {
                            return sprintf(__('<img src="/images/sticky.png" /> %s'), $label);
                    }
            }
            return $label;
    }
    add_filter('bb_topic_labels', 'my_sticky_label');

    When I do that I get [sticky] and then my image. Which is close...

  5. remove_filter('bb_topic_labels', 'bb_sticky_label', 20); worked.

    Now it has images :)

  6. You must log in to post.