When it comes to website optimization, Yoast is a popular tool that many WordPress users rely on for SEO. And while it can be incredibly helpful, there might be some instances where you want to remove the Yoast meta boxes from certain post types. Luckily, the code snippet bellow offers an easy way to do just that.

function remove_yoast_meta_boxes( $post_type ) {
    $custom_post_type= 'movies'; // Replace this with your actual post type name.
	if ( $custom_post_type === $post_type ) {
		// remove Yoast SEO metaboxes if present.
		remove_meta_box( 'wpseo_meta', $post_type, 'normal' );
		remove_meta_box( 'yoast_internal_linking', $post_type, 'side' );
	}
}
add_action( 'add_meta_boxes', 'remove_yoast_meta_boxes', 90 );
// Remember to give priority a higher number. e.g. 90 or more bigger

Let’s break it down.

First, we have a function called remove_yoast_meta_boxes that accepts one parameter: $post_type. This function is used to remove the Yoast SEO metaboxes from the post editor screen for the specified post type.

Inside the function, we define a $custom_post_type variable and set it to ‘movies’. This will be replaced with the actual post type name that you want to remove the Yoast metaboxes from.

Next, we check to see if the $custom_post_type matches the $post_type that’s passed into the function. If they match, we can go ahead and remove the Yoast meta boxes by calling remove_meta_box twice with the appropriate parameters.

The first parameter is the ID of the meta box we want to remove (wpseo_meta and yoast_internal_linking, respectively). The second parameter is the post type we want to remove the meta box from. And finally, the third parameter is the context of the meta box (‘normal’ and ‘side’, respectively).

Finally, we add the remove_yoast_meta_boxes function to the add_meta_boxes action with a priority of 90. It’s important to note that giving it a higher priority number means it will be executed later in the process, which can be useful if you’re having conflicts with other plugins or functions.