How do I link blog post authors to their BP profiles?
-
Hey,
I run a site where everyone who registers can have their own blog, and the entries all show up on the homepage. Right now those posts on the front page link to their author profiles, but I would like them to link to their BuddyPress profiles instead.
I’ve tried searching Google for a way to do so but any code I find results in a white screen on my site. The only plugin to do this is over two years old and will likely not work.
How do I do this so that I will not get a white screen?
Thanks!
-
@whiteeagle1985 The author links that are shown in the post comes from the the function which is defined in the wordpress theme. Every theme has a redefine function to print the author link. The solution can be creating a child theme and redefine the function according to your need. I am not sure which theme you are using.
I’m using the GeneratePress theme, @mastershas. I’ve created a child theme already, so I need to go and ask the theme developer which function I need to alter?
@whiteeagle1985, I checked the generatepress theme, You can put below code in you child theme’s function.php
// Change Post's Author URL to Buddypress Profile URL add_filter('generate_post_author_output','generate_post_author_output_buddyprss_url'); function generate_post_author_output_buddyprss_url( $post_author_profile_link ){ $post_author_profile_link = sprintf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span>', __( 'by','generatepress'), esc_url( bp_core_get_user_domain( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'Know more about %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ) ) ) ; return $post_author_profile_link; }
It should work.
That did work, thanks, @mastershas!
Hi @mastershas thanks so much for this! I was looking for it as well. Do you know how to allow members to edit their profiles so that the profile bio +photo on the bottom of their blog post is the same as the profile bio + photo on their buddypress page?
Hi @ottiya
Adding an author box after post which displays author bio need a different approach. I can not explain in this forum as it involves certain difficulties. But, I have written a tutorial on how to add author box below post with author bio. Kindly check and if you need help kindly ask.
ThanksHi @mastershas
Thanks so much for this and for your help with the other query I had! I was able to successfully update the member profile page. For example here
and add the profile box at the end of the post page like here
How can I add the follow button in this profile box? I tried to add this code snippet, but I got an error:
<div class="follow_button"> <div class="follow_icon"> <?php $args = array('leader_id' => bp_displayed_user_id(), 'follower_id' => bp_loggedin_user_id(),); echo bp_follow_get_add_follow_button($args); ?> </div> </div><div class="clear_follow"></div>
Also, how can I make it so that when someone clicks “view all posts by author”, it goes to their buddypress members page not the author page
It might be difficult to get the follow button on the bottom of each blog post because it seems like the follow button on the profile page is only visible for logged in members
But, the second part: making it so that when someone clicks “view all posts by author”, it goes to their buddypress members page not the author page would be really crucial because now I realized that many of the members don’t have an author page because they are not registered as a author on the wordpress backend.
Hi, the easiest way to do this is to filter the WP “author link” so that it redirects to the member’s BP profile: https://gist.github.com/dcavins/94e4989cad997d0553e8e5db37f30b40
If you want to change the template used by an article, it will depend on your theme. For instance, if you were using twentyseventeen and wanted to add the author’s link to the meta section at the end of a post, it looks like you’d want to create a new version of the function
twentyseventeen_entry_footer()
. So you could copy that function tobp-custom.php
or your child theme’sfunctions.php
file, then add the functionthe_author_posts_link()
where you want the link to appear. in any case, adding the author link to a post is a common WP task, so I’m guessing there are lots of tutorials about how to manage that part.Hi @dcavins
I added your code to the end of child theme > functions.php at the end of the code provided by @mastershas and got a syntax error
You’ll have to read the syntax error warning to see where it is. My code starts with a
<?php
tag you won’t need if you’re adding it to an existing php file, for instance, so that could be tripping you up.weird, now I can’t even see the author box anymore :S taking out the <?php tag did solve the syntax error however.
will your code redirect /author –> /member’s profile page at all instances? e.g. also when a user clicks on the author name on the top of a blog post
Yes, anywhere that the author link is created using the
the_author_posts_link()
function, the link will no longer be/author/username
but/members/username
.Hello.
I am also looking to link the author’s box to the BB profile page instead of the standard authors page.
I am using buddyboss and the buddyboss child theme.
I wish i was more proficient at coding, but i am not, so I need advice on how to do this please.How would I create the function that will link to the BB profile page?
// Change Post’s Author URL to Buddypress Profile URL
add_filter(‘generate_post_author_output’,’generate_post_author_output_buddyprss_url’);function generate_post_author_output_buddyprss_url( $post_author_profile_link ){
$post_author_profile_link = sprintf( ‘ <span class=”byline”>%1$s</span>’,
sprintf( ‘<span class=”author vcard” itemtype=”http://schema.org/Person” itemscope=”itemscope” itemprop=”author”>%1$s <span class=”author-name” itemprop=”name”>%4$s</span></span>’,
__( ‘by’,’generatepress’),
esc_url( bp_core_get_user_domain( get_the_author_meta( ‘ID’ ) ) ),
esc_attr( sprintf( __( ‘Know more about %s’, ‘generatepress’ ), get_the_author() ) ),
esc_html( get_the_author() )
)
) ;
return $post_author_profile_link;}
I just found the answer which works for me:
I would like to know how I can add the link on the members page to the author’s posts now.Thanks.
/** * Filter all instances of the_author_posts_link() so that the "author link" * no longer points to the WP author archive at /author/username * but instead points to the BuddyPress user profile at /members/username. * * @param string $link Calculated link to the author's archive. * @param int $author_id ID of the author. * @return string Link to the user's BP profile. */ add_filter( 'author_link', 'dc_bp_filter_author_link', 10, 2 ); function dc_bp_filter_author_link( $link, $author_id ) { return bp_core_get_user_domain( $author_id ); }
- You must be logged in to reply to this topic.