BuddyDev

Search

How to make custom follow button load with ajax

Tagged: 

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #17381

    Hello Brajesh,

    I’ve added the add as follow button inside my post (content-single.php) and it works, but its not using ajax like on the members directory. When I click on “Follow-Unfollow” it reloads the entire page, how can I make it follow without reloading the entire page?

    I found this links but I don’t undertand the conversations.
    https://wordpress.org/support/topic/display-followunfollow-button-anywhere/

    https://wordpress.org/support/topic/ajax-doesnt-respect-link-class-param/?replies=3#post-6018349

    https://github.com/r-a-y/buddypress-followers/wiki/Add-a-follow-button-on-a-regular-WP-page

    This is the code I added to my (content-single.php) file but it’s not loading with ajax

     <?php
    if ( function_exists( 'bp_follow_add_follow_button' ) ) :
    	if ( bp_loggedin_user_id() && bp_loggedin_user_id() != get_the_author_meta( 'ID' ) ) {
    		bp_follow_add_follow_button( array(
    			'leader_id'   => get_the_author_meta( 'ID' ),
    			'follower_id' => bp_loggedin_user_id(),
    			'link_class'  => 'post-follow-btn'
    		) );
    	}
    endif;
    ?> 

    Thank you

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #17387

    I will test and share some code by Monday.

    It should b easy.

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #17518

    Hello Brajesh,

    Any feedback on this yet

    Thanks

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #17602

    Hello Brajesh,

    I know you must be very busy, please I’m still expecting feedback on this issue.

    Thank you.

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #17603

    Hi Tosin,
    I am sorry I haven’t been able to find time to use the Follower plugin. Will do today and get back to you.

    Thank you
    Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #17623

    Hi Tosin,
    Whihc theme are you using? We will need to add following code in the js file

    
    jQuery( document).ready( function ($) {
        $(document).on("click", ".hentry .follow-button a", function() {
            bp_follow_button_action( $(this) );
            return false;
        });
    });
    
    

    Adding that will make the button work via ajax.

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #17694

    Hello Brajesh,

    THANK YOU, THANK YOU VERY MUCH The code worked perfectly I added it to the bp-follow.js file. I was wondering if its possible to add the code to child-theme.

    I am using the klein theme at https://themeforest.net/item/klein-a-nittygritty-community-theme/5418518

    God bless

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #17697

    Hi Tosin,
    I am sorry, I don’t use that theme. If they have provide a way to add custom js, it will be fine. Or you can create a custom js file and add some code in functions.php to load the file.

    Regards
    Brajesh

The topic ‘How to make custom follow button load with ajax’ is closed to new replies.

This topic is: not resolved