Viewing 2 replies - 16 through 17 (of 17 total)
  • Thread Starter Johnathan.PRO

    (@evanspress)

    My technician got it figured out. I think between the three of us he was able to come up with a final solution…

    // Facebook OG Image Tags
    add_filter( 'the_seo_framework_twitterimage_output', 'my_buddypress_profile_img' );
    add_filter( 'the_seo_framework_ogimage_output', 'my_buddypress_profile_img' );
    /**
     * Adjusts after Featured Image URL for BuddyPress profile images.
     *
     * @staticvar string $iamge
     *
     * @return string $url The Escaped Avatar Image URL.
     */
    function my_buddypress_profile_img( $image = '' ) {
    
    	static $image = null;
    
    	if ( isset( $image ) )
    		return $image;
    
    	if ( function_exists( 'bp_displayed_user_id' ) && $id = bp_displayed_user_id() ) {
    		/**
    		 * We're on a profile page and we've found the displayed user ID. Fetch avatar URL.
    		 * If no avatar is found, return empty string.
    		 */
    		$image = bp_core_fetch_avatar(array(
    			'item_id'	=>	$id,
    			'type'		=>	'full',
    			'height'	=>	512,
    			'width'		=>	512,
    			'html'		=>	false
    		));
    	}
    
    	return $image = esc_url( $image );
    }
    
    add_filter( 'the_seo_framework_twittercard_output', 'my_twittercard_adjustment' );
    /**
     * Adjusts Twitter Card type output when an image is found.
     *
     * @return string Twitter Card type
     */
    function my_twittercard_adjustment( $type ) {
    
    	if ( my_buddypress_profile_img() ) {
    		//* Get default type from settings if image is found.
    		return tsf_get_option( 'twitter_card' );
    	} else {
    		//* Evaluate further.
    		return $type;
    	}
    
    }
    
    add_filter( 'the_seo_framework_ogtype_output', 'my_ogtype_adjustment' );
    /**
     * Adjusts OG Type output when an image is found.
     *
     * @return string OG type
     */
    function my_ogtype_adjustment( $type ) {
    
    	if ( my_buddypress_profile_img() ) {
    		return 'profile';
    	} else {
    		// Evaluate further.
    		return $type;
    	}
    }
    Plugin Author Sybre Waaijer

    (@cybr)

    Great work evanspress & co!

    I was a tiny bit quicker though :P.

    I’ll be sure to include this in version 2.6.0 — and there will be no conflict between the code you’re using now and what’s coming soon (but it will do somewhat the same).

    I’m marking this topic as resolved. If you have any more questions or suggestions, feel free to ask!

    Thank you so much for your time and have a great day :).

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘FB OG:Image Tag in BuddyPress’ is closed to new replies.