Enabling BuddyPress mention auto suggestions on any page
By default, The BuddyPress mention autosuggestion only works on activity component, single post(comment) and group activity page. If you have created a custom activity page or using a shortcode plugin like BuddyPress Activity Shortcode, the autosuggestion may not work for mentions. The reason is, BuddyPress does not load the mentions javascript file everywhere( That is a good thing ). It only loads on activity component, group activity, admin pages and single post.
There are times when you want to enable it for custom component page( Say MediaPress Single Media comment page) or other things. It is easy to eanble. All you need to do is filter on "bp_activity_maybe_load_mentions_scripts" and that's all.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | add_filter( 'bp_activity_maybe_load_mentions_scripts', 'buddydev_enable_mention_autosuggestions', 10, 2 ); function buddydev_enable_mention_autosuggestions( $load, $mentions_enabled ) { if( ! $mentions_enabled ) { return $load;//activity mention is not enabled, so no need to bother } //modify this condition to suit yours if( is_user_logged_in() && bp_is_current_component( 'mediapress' ) ) { $load = true; } return $load; } |
Put the above code in your theme's functions.php or bp-custom.php and it will enable mention suggestions for the media/gallery comment on MediaPress pages. You can modify the condition to suit your own requirements.
Update: Looking for autocomplete support in BuddyPress Messages? Here is another tutorial.
Hi Brajesh,
Would it be possible to activate mention autosuggestion for bbpress?
Hi Hans,
Thank you for asking.
yes, It is. On which screens you want to enable it. We need to find out the selectors for the textarea and put a line inside document ready block of js like below
Please make sure to change the selector with actual one.
It's useful for bbp_topic_content and bbp_reply_content … So we have to edit the mention autosuggestion js itself?
Not the mentions js, We need to put it in our theme's js file. All we need to do ia load mentions.js and then in our theme's js file enable the support for textarea.
Hello,
thanks for this
you're awesome!
by the way,
how can i make it enabled in the private messaging system?
Hi Faris,
Thank you for the comment.
I have put the code as another tutorial here
https://buddydev.com/buddypress/enabling-mention-autocomplete-support-on-buddypress-compose-message-screen/
Hope that helps.
Thank you
Brajersh
How could I add this to the wordpress comments section? I'm attempting with the below code:
Footer:
Functions:
What am I doing wrong?
Perhaps I am hooked into the wrong filter, as bp_activity_maybe_load_mentions_scripts likely isn't present on the comments page?
Hi Andrew,
For comments you don't need to do it. It is enabled by default. If it is not working for you, please try checking browser console and see if there are any js errros.
Hi Brajesh,
When I enable the TinyMCE editor, the autocomplete doesn't work at all. Everything works fine when I'm on the plain text editor. Do you know what I would have to edit to enable this on tinymce? Thanks for your help!
Hi, I have tried to put your code ( thank you for that ) in my theme function because I need the auto suggestion function in another plugin. I have typed the name of the plugin instead of 'mediapress' but it seems to be wrong? Would you please be so kind to tell me what I have to do to make it working?
Thank you
Hi Denise,
you will need to type the component name(internal) or the slug(that you see after username, first part).
Pingback:Buddypress Autocomplete Message To | aldorr
Is there anyway to call mention function to profile text field?