Last active
July 5, 2022 23:53
-
-
Save thisbit/ebe34b06682227755c095d664e237622 to your computer and use it in GitHub Desktop.
Fallback image whenever there is not featured image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Auto set featured images whenever there is no featured image set | |
*/ | |
function prefix_autoset_featured_image() { | |
global $post; | |
$already_has_thumb = has_post_thumbnail( $post->ID ); | |
if ( ! $already_has_thumb ) { | |
set_post_thumbnail( $post->ID, '2023' ); // identified by attatchment ID | |
} | |
} | |
add_action('the_post', 'prefix_autoset_featured_image'); | |
add_action('save_post', 'prefix_autoset_featured_image'); | |
add_action('draft_to_publish', 'prefix_autoset_featured_image'); | |
add_action('new_to_publish', 'prefix_autoset_featured_image'); | |
add_action('pending_to_publish', 'prefix_autoset_featured_image'); | |
add_action('future_to_publish', 'prefix_autoset_featured_image'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment