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

#1099597
  • 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.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this ticket.