AI Verified

Name

Default featured image

About

This code defines a function named default_post_metadata__thumbnail_id that modifies the value of the _thumbnail_id metadata field for a post. The function takes five arguments: $value: The current value of the metadata field. $object_id: The ID of the object (e.g., post) to which the metadata field belongs. $meta_key: The key of the metadata field. $single: A boolean value indicating whether the metadata field is a single field or an array of fields. $meta_type: The type of object (e.g., "post") to which the metadata field belongs. The function first checks if the $meta_key variable is equal to _thumbnail_id. If it is, the function sets the $value variable to 17602, which is the ID of the default image. Finally, the function returns the modified $value variable. After defining the function, the code registers it as a filter for the default_post_metadata hook. This means that whenever WordPress retrieves the default value for a _thumbnail_id metadata field for a post, it will use the value returned by the default_post_metadata__thumbnail_id function instead.

Language

PHP

Rating

Voted: 3 by 3 user(s)

How to Setup Snippet

add into functions.php file and pass the id of the image as the value

Codevault

justin's vault

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: Not Specified

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

04/07/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Default featured image

 
                    
1function default_post_metadata__thumbnail_id( $value, $object_id, $meta_key,
2 $single, $meta_type )
3{
4 if ( '_thumbnail_id' == $meta_key )
5 {
6 $value = 17602; // the ID for the default image
7 }
8 
9 return $value;
10}
11add_filter( 'default_post_metadata', 'default_post_metadata__thumbnail_id', 10, 5 );

3

Comments

Related Snippets

Please see some snippets below related to this snippet..

General

AI Verified

0

Change post name in dashboard

Added: 7 months ago

Last Updated: 6 months ago

General

AI Verified

0

Disable Admin Bar for All Users Except Admins

Added: 8 months ago

Last Updated: 3 weeks ago

General

AI Verified

0

Disable Emojis

Added: 9 months ago

Last Updated: 9 months ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

3

Default featured image

Added: 1 year ago

Last Updated: 2 weeks ago

This code defines a function named default_post_metadata__thumbnail_id that modifies the value of the _thumbnail_id metadata field for a post. The function takes five arguments: $value: The current...

WordPress Admin

AI Verified

2

Completely Disable Comments

Added: 1 year ago

Last Updated: 4 months ago

This will disable comments on the entire site

WordPress Admin

AI Verified

1

Disable Automatic Updates

Added: 1 year ago

Last Updated: 9 months ago

This will disable automatic updates