Custom og:image

#545740
  • Resolved Osama Amin
    Rank Math free

    hello,

    We are using a jet-engine plugin (profile builder) to build user’s pages. The profile pages work under a main page.

    for example, the archive page is:
    https://wordpress-965060-3372111.cloudwaysapps.com/members/
    and the profile page is
    https://wordpress-965060-3372111.cloudwaysapps.com/members/58/profile/

    When we share a profile page, it takes the main page featured image (the archive page).
    We need to make the profile pages share the user’s image that is coming from member_profile_picture meta field for every user.

    So we need to replace the og:image for every link that includes /profile/, for example, and the og:image should get the user profile image that comes from member_profile_picture meta field.
    https://share.getcloudapp.com/Jrup6zLk

    we have tried to do that, but unfortunately, we are not good at coding, is that something you can help us to do, please?

    Thank You!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Osama Amin
    Rank Math free

    Update:

    We have used this snippet, and it worked, but the default opengraph image in Rankmath overrides this code, so we need to disable the default image inside rank math to make this code work.

    Can we update something to use both (this code for profiles and rank math default image for others)?

    function cwpai_fallback_og_image() {
    if (strpos($_SERVER[‘REQUEST_URI’], ‘profile’) !== false && !has_post_thumbnail()) {
    $user_id = explode(‘/’, $_SERVER[‘REQUEST_URI’])[2];
    $user_meta = wp_get_attachment_image_src(get_user_meta($user_id, ‘member_profile_picture’, true), ‘full’);
    if ($user_meta) {
    echo ‘<meta property=”og:image” content=”‘ . $user_meta[0] . ‘” />’;
    }
    }
    }
    add_action(‘wp_head’, ‘cwpai_fallback_og_image’, 1);

    Nigel
    Rank Math business

    Hello,

    Thank you for contacting Rank Math for help with changing the opengraph image of your posts.

    The function you created adds a second opengraph image without removing the existing Rank Math one. Please use the filter to modify Rank Math opengraph image instead: https://rankmath.com/kb/filters-hooks-api-developer/#change-opengraph-image

    Hope that helps. Please let us know if you have questions.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘Custom og:image’ is closed to new replies.