Skip to:
Content
Pages
Categories
Search
Top
Bottom

Change mentionname to displayname in “cover-image-header.php”


  • richard.miller
    Participant

    @richardmiller-1

    I have a child theme, and am attempting to change the mention name (the “@” user name) to the display name (full name, first and last).

    Looks like this is the place to do it:
    buddypress\members\single\cover-image-header.php

    And this looks like the line to edit:
    <h2 class=”user-nicename”>@<?php bp_displayed_user_mentionname(); ?></h2>

    I’ve changed the “mentionname” in that line to “displayname”, but it breaks the page.

    What should I be using, and in the future, where should I look for this kind of answer?

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

  • richard.miller
    Participant

    @richardmiller-1

    And as long as we’re in this template, how/where can I get rid of the title of these pages?

    Shows up like this at the top of the page:

    <h1 class=”entry-title main_title”>First Last</h1>


    richard.miller
    Participant

    @richardmiller-1

    Bump?


    Boone Gorges
    Keymaster

    @boonebgorges

    Hi @richardmiller-1 – The purpose of the @username part of the interface is to tell other users how to mention the user when posting new activity items, etc. It’s possible to change the value that’s displayed here, but if you do, and if users then use that text to “mention” others, then things like auto-linking of @-mentions and @-mention notifications will break, since BP doesn’t know by default how to search by display names.

    If you just want to change the display, then you should copy the cover-image-header.php template to your own child theme, and then change the line you’ve referenced to:

    
    <h2 class=”user-nicename”>@<?php echo bp_core_get_user_displayname( bp_displayed_user_id() ); ?></h2>
    

    It might be possible to retool some of the @-mention plumbing so that notifications etc work. You’d want to start by filtering bp_activity_mentioned_users(), and copying some of the logic in bp_activity_find_mentions() but with modified regex + user lookup. (This is going to be hard because, among other things, display names are not necessarily unique across a network, so @Richard could refer to multiple people. But that depends on the nature of your network.)

    The h1 at the top of the profile page is generated in a weird way, as part of BP’s theme compatibility system. It’s not directly generated by BP, but comes from your WP theme; BP is faking the theme into thinking that the user’s display name is the title of the WP page, so that your theme’s page.php template outputs it as the_title(). There are various workarounds for this. One is to tap into BP’s template hierarchy, so that WP would use a separate template file for single member pages. See https://codex.buddypress.org/themes/theme-compatibility-1-7/template-hierarchy/#single-member-pages for details. Basically, you’d copy page.php to buddypress/members/single/index.php, and remove the call to the_title(). A simpler solution is to hide with CSS:

    
    .bp-user .entry-title {
    	display: none;
    }
    

    richard.miller
    Participant

    @richardmiller-1

    Thanks for the thorough and detailed response!

    Unfortunately, I haven’t been able to make your advice work.

    @username display:

    I replaced the indicated line of code in my child theme’s cover-image-header.php with yours. Not only does the Display Name not appear (only the “@” appears), but everything following it (tabs of user activity, etc) disappears. The page just ends.

    Page title:

    1) I copied the WP’s page.php file into my child theme’s buddypress/members/single/ directory and removed this line of code:<h1 class=”entry-title main_title”><?php the_title(); ?></h1>
    No effect.

    I tried hiding the title with CSS – that didn’t work either.

    Any insight into what I may be doing wrong would be appreciated.

    (all caches purged, alternate browsers tried, etc.)


    Boone Gorges
    Keymaster

    @boonebgorges

    > I replaced the indicated line of code in my child theme’s cover-image-header.php with yours. Not only does the Display Name not appear (only the “@” appears), but everything following it (tabs of user activity, etc) disappears. The page just ends.

    Sorry, there was a typo in my original response. I wrote bp_displayed_user-id() instead of bp_displayed_user_id().

    When the page stops rendering like this, it means that there’s been a PHP fatal error. If you’re going to be modifying PHP files, it’s a good idea to get familiar with either your server’s PHP error log, or the WP_DEBUG constant. See https://codex.wordpress.org/Debugging_in_WordPress

    > Any insight into what I may be doing wrong would be appreciated.

    Hard to know exactly what is going on without seeing your site. For the template, my guess is that you have copied things into the incorrect location in your child theme. The template overrides only work if the directory structure matches directly, as described on the codex page linked above. So, the path should be something like wp-content/themes/your-theme/buddypress/members/single/index.php.

    For the CSS, it could be that your theme is using different CSS selectors for page titles. (.entry-title is used by some of the WordPress default themes, so I guessed that it might be in use on your theme too.) Use your browser’s inspector to get the proper selector. Here’s a useful tutorial: http://toolsqa.com/selenium-webdriver/finding-elements-using-browser-inspector/ Once you have found the id/class of the element, replace .entry-title in my snippet with that.


    richard.miller
    Participant

    @richardmiller-1

    Thanks!

    Fixing the code typo worked, and I’d misread your directions to change the duplicated “page.php” filename to “index.php”.

    All good now. 🙂


    Boone Gorges
    Keymaster

    @boonebgorges

    Cool – thanks for reporting back!

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