Hello @nexusfred,
Thank you so much for getting in touch.
Yes, it is possible with the help of our filter code. Please see the code below to modify the social images that our plugin generates:
add_filter( 'rank_math/opengraph/facebook/image', function( $attachment_url ) { $post = get_post($_POST['post_id']); if(get_field('YOUR_IMG_FIELD_URL', $post->ID)){ return get_field('YOUR_IMG_FIELD_URL', $post->ID); } else{ return $attachment_url; } }); add_filter( 'rank_math/opengraph/twitter/image', function( $attachment_url ) { $post = get_post($_POST['post_id']); if(get_field('YOUR_IMG_FIELD_URL', $post->ID)){ return get_field('YOUR_IMG_FIELD_URL', $post->ID); } else{ return $attachment_url; } });
Please note that you have to change the field name to the correct one.
You may refer to this guide on how to add filters to your website: https://rankmath.com/kb/wordpress-hooks-actions-filters/
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Thanks, I will try that !
Glad that helped, @nexusfred!
Please do not hesitate to let us know if you need our assistance with anything else.
Thanks a lot. I replace “$post = get_post($_POST[‘post_id’]);” by “$post_id = get_the_ID();” :
add_filter( 'rank_math/opengraph/facebook/image', function( $attachment_url ) {
$post_id = get_the_ID();
if( get_field('YOUR_IMG_FIELD_URL', $post_id )){
return get_field( 'YOUR_IMG_FIELD_URL', $post_id );
} else { return $attachment_url;
}
});
add_filter( 'rank_math/opengraph/twitter/image', function( $attachment_url ){
$post_id = get_the_ID();
if( get_field('YOUR_IMG_FIELD_URL', $post_id)){
return get_field( 'YOUR_IMG_FIELD_URL', $post_id );
}else{
return $attachment_url;
}
});
-
This reply was modified 2 years, 2 months ago by
nexusfred.
Hello @nexusfred,
Thanks for the update. Let us know how that goes.
In the meantime, please do not hesitate to let us know if you need our assistance with anything else.