Split: Set a custom image field as the default social share image for post type

#1099597
  • Resolved Ahmed Mamdouh
    Rank Math free

    I’m using Voxel wordpress theme (getvoxel.io). How to use a custom image field (logo) in a custom post type called (places) as the default social share image?. I also need a code script which I can add in code snippets plugins not in the theme function file. thanks for your help.

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    We have separated your concern into a new ticket so we can assist you accordingly.

    You can use and customize this filter to set a default image from a custom field:

    add_filter( "rank_math/opengraph/facebook/image", function( $attachment_url ) {
    	if(get_post_type() == 'places') { //name of the post type
    		$attachment_url = get_field('field-name', get_queried_object_id()); //name of the custom field
    		return $attachment_url;
    	}
    	return $attachment_url;
    });

    Also, the filter can be added to your site using the Code Snippets plugin
    https://rankmath.com/kb/wordpress-hooks-actions-filters/code-snippets-plugin

    Hope that helps.

    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 1 replies (of 1 total)

The ticket ‘Split: Set a custom image field as the default social share image for post type’ is closed to new replies.