Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Rank Math Support

    (@rankmathsupport)

    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.

    Thread Starter nexusfred

    (@nexusfred)

    Thanks, I will try that !

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Glad that helped, @nexusfred!

    Please do not hesitate to let us know if you need our assistance with anything else.

    Thread Starter nexusfred

    (@nexusfred)

    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 1 year, 2 months ago by nexusfred.
    Plugin Support Rank Math Support

    (@rankmathsupport)

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘ACF Image Field as default social image’ is closed to new replies.