Skip to:
Content
Pages
Categories
Search
Top
Bottom

Change “title” attribute in Who’s Online Widget


  • ywickham
    Participant

    @ywickham

    Hi,

    Is there a way to change the title attribute in the links for the Who’s Online widget so that it uses the username instead of the user’s full name?

    For example, what I have:

    
    <a href="http://website.com/members/lajefa/" title="Jane Doe">...
    

    What I’d like to see:

    
    <a href="http://website.com/members/lajefa/" title="lajefa">...
    

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

  • danbp
    Participant

    @danbp

    The easiest way would be to create your own widget, as this widget is in a core file (bp-members/bp-members-widgets.php). Then you can ignore the built in widget and use yours.

    Line 307 > 309 is a div containing what you have to modify.

    <div class="item-avatar">
       <a href="<?php bp_member_permalink(); ?>" title="<?php bp_member_name(); ?>"><?php bp_member_avatar(); ?></a>
    </div>

    Change bp_member_name() to bp_member_user_nicename()

    Code related to who’s online goes from line 247 to 390.

    – Copy/paste it to bp-custom.php
    – change class name to something unique. ie. class My_Whos_Online_Widget extends WP_Widget
    – in __construct function, in $name replace (BuddyPress by Custom)
    – modify the div content by replacing bp_member_name() by bp_member_user_nicename()

    Done !
    You have to register the new widget. In bp-custom

    function register_my_custom_widget() {
        register_widget( 'My_Whos_Online_Widget' );
    }
    add_action( 'widgets_init', 'register_my_custom_widget' );

    Go to Appearance > Widget and select (Custom) Who’s Online Widget.

    Finito ! 🙂

    WP codex reference


    ywickham
    Participant

    @ywickham

    Thank you! This worked perfectly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change “title” attribute in Who’s Online Widget’ is closed to new replies.
Skip to toolbar