• Resolved teeboy4real

    (@teeboy4real)


    Hello

    I want to migrate from yoast to AIOSEO but I have some custom buddypress code for yoast in my functions.php file. Does AIOSEO support buddypress, this is the custom code below

    // Yoast SEO title fix //
    function buddydev_disable_wp_seo_title_filter() {
     
        if ( class_exists( 'WPSEO_Frontend' ) && is_buddypress()  ) {
            $instance = WPSEO_Frontend::get_instance();
     
            if ( has_filter( 'wp_title', array( $instance, 'title' ) ) ) {
                remove_filter( 'wp_title', array( $instance, 'title' ), 15, 3 );
            }
     
            if ( has_filter( 'pre_get_document_title', array( $instance, 'title' ) ) ) {
                remove_filter( 'pre_get_document_title', array( $instance, 'title' ), 15 );
            }
        }
     
    }
    add_action( 'bp_template_redirect', 'buddydev_disable_wp_seo_title_filter' );
    
    
    
    // Yoast SEO title fix meta description //
    add_filter('wpseo_metadesc','bpdev_bp_items_metadesc');
    function bpdev_bp_items_metadesc( $desc ){
      // if it is not buddypress page or buddypress directory pages let the plugin do its work
     
        if( bp_is_blog_page() || bp_is_directory() )
          return $desc;
        //we do not cover directory as directory meta can be customized from pages->Edit screen
     
        //now, let us check if we are on members page
     
        if(bp_is_user()){
     
            //what should me the description, I am going to put it like Profile & Recent activities of [user_dsplay_name] on the site [sitename]
            //if you are creative, you can use some xprofile field and xprofile_get_field_data to make it better
           $desc = sprintf(' %s\'s Profile & Recent activities on %s ', bp_get_displayed_user_fullname(), get_bloginfo('name'));
        } elseif( bp_is_active( 'groups' ) && bp_is_group() ){//for single group
            //let us use group description
            $desc = bp_get_group_description(groups_get_current_group());
     
        }
        //do it for other components
         //ok, so you can go and do the same for all the other pages
        //finally return the description
        return $desc;
     
    }
    
    
    
    
    
    /* Modify members directory title for the current member type */
    function buddydev_modify_member_type_directory_title( $title ) {
     
        if ( ! bp_is_members_directory() ) {
            return $title;
        }
     
        $member_type = bp_get_current_member_type();
     
        if ( ! $member_type ) {
            return $title;
        }
     
        $type_object = bp_get_member_type_object( $member_type );
     
        $sep = apply_filters( 'document_title_separator', '-' );
        // we are reusing the buddypress()->pages->members->id page's title,
        // you can call get_post() over it and do any extra manipulation
        $title['title'] = $title['title'] . ' ' . $sep . ' ' . $type_object->labels['name'];
     
        return $title;
    }
    add_filter( 'document_title_parts', 'buddydev_modify_member_type_directory_title', 1000 );

    This code was provided by the team at https://buddydev.com/

    Thanks

Viewing 1 replies (of 1 total)
  • Plugin Support Shivam Tyagi

    (@shivamtyagi)

    Hi @teeboy4real,

    While AIOSEO does not currently have native support for BuddyPress, I can provide you with a similar snippet that you can use with AIOSEO to achieve similar functionality to what your current custom code with Yoast SEO offers. Here’s the adapted snippet for AIOSEO:

    add_action( 'bp_template_redirect', function () {
        if ( is_buddypress() ) {
            add_filter( 'aioseo_disable_title_rewrites', '__return_true' );
        }
    } );
    
    add_filter( 'aioseo_description', function ( $desc ) {
        if ( bp_is_blog_page() || bp_is_directory() ) {
            return $desc;
        }
    
        if ( bp_is_user() ) {
            $desc = sprintf( ' %s\'s Profile & Recent activities on %s ', bp_get_displayed_user_fullname(), get_bloginfo( 'name' ) );
        }
    
        if ( bp_is_active( 'groups' ) && bp_is_group() ) {
            $desc = bp_get_group_description( groups_get_current_group() );
        }
    
        return $desc;
    } );
    
    add_filter( 'document_title_parts', function ( $title ) {
        if ( ! bp_is_members_directory() ) {
            return $title;
        }
    
        $member_type = bp_get_current_member_type();
        if ( ! $member_type ) {
            return $title;
        }
    
        $type_object = bp_get_member_type_object( $member_type );
        $sep = apply_filters( 'document_title_separator', '-' );
        $title['title'] = $title['title'] . ' ' . $sep . ' ' . $type_object->labels['name'];
    
        return $title;
    }, 1000 );

    This code should replicate the behavior of your existing custom code for AIOSEO. It’s important to note that while this snippet should work, it doesn’t guarantee that it will produce the exact meta titles and descriptions you’re aiming for. This is because we currently don’t have a dedicated integration for BuddyPress.

    If you’re looking for fully customizable support for BuddyPress, it might be worth waiting for our future updates where we plan to include BuddyPress integration.

Viewing 1 replies (of 1 total)
  • The topic ‘Support for buddypress’ is closed to new replies.