RankMath Default OpenGraph for User Listing / User Profile Page

#569707
  • Resolved Anonymous
    Rank Math free

    Hello,

    I’m looking for a solution to assign the default image for the OpenGraph.

    Loom Video for Demo
    https://www.loom.com/share/a72ba739c9934d688384fa087b8e3a9f

    Looking For
    – Default open graph image not working
    – Ability to assign an open graph image for a specific cpt
    – or ability to use the first image on the page as the opengraph?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello,

    Thank you for your query and we are so sorry about the trouble this must have caused.

    It seems that Rank Math is currently disabled on your website.

    We would like to check the issue within your admin dashboard but the access you shared doesn’t allow us to enter the wp-admin dashboard.

    Could you please elevate the access to the admin level so we can fully access the settings and investigate the issue?

    Looking forward to helping you with this one.

    Anonymous
    Rank Math free

    Hello Jeremy,

    The Role has been updated to Admin.

    Thank you,
    wiL

    Hello,

    Thank you for providing additional information.

    I did a quick test on the admin with Rank Math activated and yes, once Rank Math is activated, the og:image is different. Though, in the user profile in WP dashboard it shows the default og:image you selected under Rank Math.

    Would you please run this troubleshooting guide to be sure that there’s no conflict between other plugin / theme : https://rankmath.com/kb/check-plugin-conflicts/

    Do let us know if you find some plugin conflicting with Rank Math. If not, then we’ll take a closer look on the settings.

    Looking forward to helping you.

    Thank you

    Anonymous
    Rank Math free

    Hello Sandeepan,

    I can confirm that with the bare minimum plugins installed, it still shows a different image for og:image.

    Code Screenshot of Rank Math
    https://app.screencast.com/A5oypw9PHxIGU

    Plugins Enabled
    – Elementor/Pro
    – JetEngine
    – Hello Theme
    – Rank Math

    I can’t find that image on RankMath unfortunately.

    Thanks,
    wiL

    Hello,

    Thank you for your patience.

    It looks like you’re using custom implementation on your user profiles area for images and assuming this is why Rank Math is unable to capture the correct image.

    However, you can use the following filter to set the default OpenGraph image forcefully everywhere.

    add_filter('rank_math/opengraph/pre_set_content_image', function() {
    	return true;
    });

    Please disable the Code Snippet named “User OpenGraph” in the code snippet plugin to avoid duplicate og:image issues.

    However, the following filter can be used to set the user image to the OpenGraph image (Affects only for the members/users):

    add_filter( "rank_math/opengraph/facebook/image", function( $attachment_url ) {
    	
       if ( ! function_exists( 'jet_engine' ) || ! jet_engine()->modules->is_module_active( 'profile-builder' ) ) {
            return;
        }
        
        $module = \Jet_Engine\Modules\Profile_Builder\Module::instance();
        
        if ( ! $module->query->is_single_user_page() ) {
            return;
        }
        
        $user_id = $module->query->get_queried_user_id();
        
        $image_id = get_user_meta( $user_id, 'business_logo', true );
        
        if ( ! $image_id ) {
            return;
        }
        
    	$attachment_url =  wp_get_attachment_url( $image_id );
    	
    	return $attachment_url;
    });
    
    add_filter( "rank_math/opengraph/twitter/image", function( $attachment_url ) {
    	
    	 if ( ! function_exists( 'jet_engine' ) || ! jet_engine()->modules->is_module_active( 'profile-builder' ) ) {
            return;
        }
        
        $module = \Jet_Engine\Modules\Profile_Builder\Module::instance();
        
        if ( ! $module->query->is_single_user_page() ) {
            return;
        }
        
        $user_id = $module->query->get_queried_user_id();
        
        $image_id = get_user_meta( $user_id, 'business_logo', true );
        
        if ( ! $image_id ) {
            return;
        }
        
    	$attachment_url =  wp_get_attachment_url( $image_id );
    	
    	return $attachment_url;
    });

    #3 To change OpenGraph image for any specific CPT:

    add_filter( "rank_math/opengraph/facebook/image", function( $attachment_url ) {
    	
      $post_type = get_post_type(get_queried_object());
    	
    	if ($post_type == 'your_post_type') { //replace 'your_post_type' with your CPT slug
        
    		$attachment_url =  'YOUR IMAGE URL HERE';
    	
    	}
    	return $attachment_url;
    });
    
    add_filter( "rank_math/opengraph/twitter/image", function( $attachment_url ) {
    	
    	$post_type = get_post_type(get_queried_object());
    	
    	if ($post_type == 'your_post_type') { //replace 'your_post_type' with your CPT slug
        
    		$attachment_url =  'YOUR IMAGE URL HERE';
    	
    	}
    	return $attachment_url;
    });

    Let us know how it goes. Looking forward to helping you.

    Thank you.

    Anonymous
    Rank Math free

    Thank for this!

    I’m excited for the fix because there will be more website with directory listings and profile pages that we’ll be creating in the future and we’d like to suggest RankMath as their SEO application of choice.

    +++

    I tried it out but unfortunately the code didn’t work.

    Was there anything I need to do other than changing the metaname of the logo (which I saw it was already updated “business_logo”)

    I disabled the Crocoblock Snippet and enabled your RankMath Snippet.
    https://app.screencast.com/ulODRqZa5JXwQ

    But it is still pulling the random image for opengraph that is not set on RankMath.
    https://app.screencast.com/rC1ksrfY22g2g

    Is there anything else I’m missing?

    Much Appreciated,
    wiL

    Hello,

    Yes, what you were missing is to purge the site cache.

    No problem! I’ve done that for you and now it’s reflecting the correct image for your member profile page:
    https://developers.facebook.com/tools/debug/?q=https%3A%2F%2Fcompanionanimalnetwork.com%2Fdirectory%2FJessica%2Fmember-profile%2F

    Hope that helps, and please do not hesitate to let us know if you need our assistance with anything else.

    Thank you.

    Anonymous
    Rank Math free

    Ah, that’s fantastic!

    Definitely a solution for our other directory sites.

    Thanks so much! 🙂

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 9 replies - 1 through 9 (of 9 total)

The ticket ‘RankMath Default OpenGraph for User Listing / User Profile Page’ is closed to new replies.