Hello,
Thank you for contacting Rank Math and bringing your concern to our attention.
Yes, you can use this filter to update the social media image (Opengraph) from your custom field:
add_filter( 'rank_math/opengraph/facebook/image', 'change_opengraph_image_custom_field' );
function change_opengraph_image_custom_field( $attachment_url ) {
global $post;
if (is_page()) { //update to match your page/post type
$attachment_url = get_field( 'custom-field-name', $post->ID ); //update to the actual custom field name
}
return $attachment_url;
}
Here’s how you can add filter/hook to your WordPress site:
https://rankmath.com/kb/wordpress-hooks-actions-filters/
Hope that helps.
this is great thank you – one more question please:
Can the default SEO image be assigned as the featured image for a specific custom post type?
For example: the featured image would automatically be assigned for CPT called “NEWS”
Hello,
Sorry, but this type of customization falls outside the scope of our support. However, if the default image you’re referring to will be the same or taken from the same custom field, you may try this code:
add_action( 'save_post', function ( $post_id, $post, $update) {
$defaultImage = get_field( 'custom-field-name', $post->ID );
if (! has_post_thumbnail($post_id) && ! empty($defaultImage) && get_post_type($post_id) == 'news') {
$attachment_id = attachment_url_to_postid($defaultImage);
if ($attachment_id) {
set_post_thumbnail($post_id, $attachment_id);
}
}
}, 999, 3 );
Hope that helps.
grateful for your help – thank you 🙂
Hello,
You’re welcome.
We are super happy that we addressed your concerns. If you have any other questions in the future, know that we are here to help you.
If you don’t mind us 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 have another question in the future, please feel free to create a new forum topic. It will be our pleasure to assist you again.
Thank you.