front page › Forums › Community › Adding text after my cred badges
- This topic has 8 replies, 3 voices, and was last updated 1 year, 1 month ago by
She Makes Webthings.
- AuthorPosts
- December 23, 2019 at 14:51 #48072
She Makes Webthings
Hello, I am using mycred with buddypress and have it appearing in the users profile. I would like to add a link after the badges that would like to a page that explains about badge earnings. Can someone help? Thank you.
December 24, 2019 at 11:33 #48511Ammar Ahmed
Hi,
You can add the text after the badge image using mycred_badge_image filter follow the documentation:
https://codex.mycred.me/filters/mycred_badge_image/Thanks,
myCred SupportDecember 27, 2019 at 10:44 #48676She Makes Webthings
Do you think you can share another example? I can’t seem to figure it out. If I edit the snippet, the badges all disappear:
function mycred_text ( $html, $image, $badge_object ) { echo '' ; } add_filter( 'mycred_badge_image', 'mycred_text', 10, 3 );
December 28, 2019 at 19:13 #48866You need to edit the
$html
and then make sure toreturn
it.December 31, 2019 at 01:59 #49156She Makes Webthings
Sorry I have a ticket open for this as well. I’m not sure why I’m not getting notifications from the support forum…
Thank you for your response…but I honestly don’t understand. The snippet provided in your link is too complicated for someone who isn’t very familiar with coding in php. I am seeking support to add HTML after the badges, but am only getting clues that don’t really help. Thanks anyway.
January 2, 2020 at 16:47 #49493Hello,
The snippet is actually very straight forward, did you see my message above where I said that it’s the$html
variable that you need to edit and that you need to make sure toreturn
it ?For example:
function mycred_text ( $html, $image, $badge_object ) { return '<some html here that comes before or as a> <prefix>' . $html . '<some other html here that comes after or as a suffix closing the> </prefix>'; } add_filter( 'mycred_badge_image', 'mycred_text', 10, 3 );
Hope this helps you better.
Cordially, M.
January 2, 2020 at 16:50 #49499Or more clearly:
function mycred_text ( $html, $image, $badge_object ) { $html = '<some html here that comes before or as a> <prefix>' . $html . '<some other html here that comes after or as a suffix closing the> </prefix>'; return $html; } add_filter( 'mycred_badge_image', 'mycred_text', 10, 3 );
January 3, 2020 at 22:22 #49648She Makes Webthings
As I mentioned, I don’t know php so I appreciate you taking the time to explain the $html and return function. But this snippet adds text after every badge. I am just trying to add text after the badge ‘row’ on the users profile. Can this be done or do I need to use CSS to achieve that? Thank you.
January 7, 2020 at 21:25 #50109She Makes Webthings
If anyone needs help with this. The correct code is as follows:
function add_content_after_mycred_users_badges( $user_id, $users_badges ) { echo "<div>Your Text Here</div>"; } add_action( 'mycred_after_users_badges', 'add_content_after_mycred_users_badges', 10, 2 );
- AuthorPosts
You must be logged in to reply to this topic.