Custom og:image

#545740
Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.