Title: Remove DFI from REST API?
Last modified: October 16, 2025

---

# Remove DFI from REST API?

 *  Resolved [ChrisL](https://wordpress.org/support/users/chrslcy/)
 * (@chrslcy)
 * [7 months, 4 weeks ago](https://wordpress.org/support/topic/remove-dfi-from-rest-api/)
 * How to ensure that the DFI does not appear in the REST API? I only want it to
   appear on the website.
 * Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Jan-Willem](https://wordpress.org/support/users/janwoostendorp/)
 * (@janwoostendorp)
 * [7 months, 3 weeks ago](https://wordpress.org/support/topic/remove-dfi-from-rest-api/#post-18687294)
 * Hi Chris,
 * Currently I’m on a vacation. So I cannot provide a in dept answer now. It’s probably
   possible with custom code. There are several code snippets in the FAQ.
 * The hard part is that the wp-admin also uses the rest API when editing a post.
   
   Please let me know if you need me to create the custom snippet. I could create
   that somewhere next week.
 *  Thread Starter [ChrisL](https://wordpress.org/support/users/chrslcy/)
 * (@chrslcy)
 * [7 months, 1 week ago](https://wordpress.org/support/topic/remove-dfi-from-rest-api/#post-18709266)
 * Hi Jan,
 * A snippet to disable DFI for REST API would be great, if you don’t mind. My attempts
   with AI have failed. 😐
 * Thank you.
 * A few extra settings would go a long way if you are considering extra features,
   such as checkboxes to..
   Disable DFI for postsDisable DFI for pagesDisable DFI
   for {registered custom post type 1}, etcDisable DFI for REST API
 * Great plugin all the same!
 *  Plugin Author [Jan-Willem](https://wordpress.org/support/users/janwoostendorp/)
 * (@janwoostendorp)
 * [7 months, 1 week ago](https://wordpress.org/support/topic/remove-dfi-from-rest-api/#post-18709279)
 * Hi Chris,
 * I’ll get back with the snippet on Wednesday.
 * A option per post-type/category ect had been noted before.
   I’ve been thinking
   about it, might happen next year.
 *  Plugin Author [Jan-Willem](https://wordpress.org/support/users/janwoostendorp/)
 * (@janwoostendorp)
 * [7 months ago](https://wordpress.org/support/topic/remove-dfi-from-rest-api/#post-18716807)
 * Hi Chris,
 * Below is the code that disables DFI in the rest API
 * In your `wp-content/plugins/` folder create a file named: `dfi-exclude-rest.php`
   
   With the following code:
 *     ```wp-block-code
       <?php/** * Plugin Name: Default Featured Image - Random post image * Plugin URI:  https://wordpress.org/support/topic/multiple-featured-images-6/ * Version:     1.0 */add_filter( 'dfi_thumbnail_id', 'dfi_random_image', 10, 2 );function dfi_random_image( $dfi_id, $post_id ) {	if ( get_post_type( $post_id ) !== 'post' ) {		return $dfi_id; // This is not a post, we only check posts.	}	$random_image_ids = array(		123, # Add your image id's in this array.		456,	);	return $random_image_ids[ array_rand( $random_image_ids ) ];}
       ```
   
 * After that, go to the WP-Admin > Plugins and activate the new plugin.
   That’s 
   it.
 * Let me know how it goes!
 *  Thread Starter [ChrisL](https://wordpress.org/support/users/chrslcy/)
 * (@chrslcy)
 * [7 months ago](https://wordpress.org/support/topic/remove-dfi-from-rest-api/#post-18718101)
 * Hi Jan,
 * Are you sure you pasted the correct function? That appears to replace the dfi
   with a random image and I see no reference to the REST API.
   Thanks,
 * Chris
 *  Plugin Author [Jan-Willem](https://wordpress.org/support/users/janwoostendorp/)
 * (@janwoostendorp)
 * [6 months, 4 weeks ago](https://wordpress.org/support/topic/remove-dfi-from-rest-api/#post-18719909)
 * Sorry this is the correct code:
 *     ```wp-block-code
       <?php/** * Plugin Name: Default Featured Image - Exclude rest API * Plugin URI:  https://wordpress.org/support/topic/remove-dfi-from-rest-api/ * Version:     1.0 */add_filter( 'dfi_thumbnail_id', 'dfi_disable_in_rest', 10, 2 );function dfi_disable_in_rest( $dfi_id, $post_id ) {    if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {		return 0; // Empty image ID for rest requests.	}    return $dfi_id; // the original featured image id.}
       ```
   
 *  Thread Starter [ChrisL](https://wordpress.org/support/users/chrslcy/)
 * (@chrslcy)
 * [6 months, 3 weeks ago](https://wordpress.org/support/topic/remove-dfi-from-rest-api/#post-18722115)
 * That worked a treat. Thank you very much!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Remove DFI from REST API?’ is closed to new replies.

 * ![](https://ps.w.org/default-featured-image/assets/icon-256x256.jpg?rev=1058491)
 * [Default Featured Image](https://wordpress.org/plugins/default-featured-image/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/default-featured-image/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/default-featured-image/)
 * [Active Topics](https://wordpress.org/support/plugin/default-featured-image/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/default-featured-image/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/default-featured-image/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [ChrisL](https://wordpress.org/support/users/chrslcy/)
 * Last activity: [6 months, 3 weeks ago](https://wordpress.org/support/topic/remove-dfi-from-rest-api/#post-18722115)
 * Status: resolved