aiosp_opengraph_default_image_type

Need help with this?
Purchase All in One SEO Pack Pro to get dedicated support from us.

Buy Now

The All in One SEO Pack aiosp_opengraph_default_image_type filter hook.

This filter can be used to set the Open Graph image for a specific post type.  This is especially useful for users of WooCommerce who wish to use the Product Image as the OG image.

Usage

Example 1 – Use the featured image as the og:image for the xxx post type

add_filter( 'aiosp_opengraph_default_image_type', 'change_opengraph_default_image_type', 10, 2 );

function change_opengraph_default_image_type( $img_type, $post ) {
	// use the featured image for a hypothetical post type 'xxx'
	if ( 'xxx' === $post->post_type ) {
		return 'featured';
	}
	return $img_type;
}

Example 2 – Use a custom image as the og:image for the xxx post type

add_filter( 'aiosp_opengraph_default_image', 'change_opengraph_default_image', 10, 2 );

function change_opengraph_default_image( $thumbnail, $post ) {
	// use a custom image for a hypothetical post type 'xxx'
	if ( 'xxx' === $post->post_type ) {
		return 'https://semperplugins.com/wp-content/uploads/2016/05/semper-plugins-logo.png';
	}
	return $thumbnail;
}

For instructions on how to use this code, please refer to our FAQ here.

  • Was this helpful ?
  • YesNo