Home / Admin / Setting a Default Featured Image for Post Submissions
Duplicate Snippet

Embed Snippet on Your Site

Setting a Default Featured Image for Post Submissions

This snippet is used to assign a default image that'll serve as the featured image for user-submitted posts on your site.

<10
Code Preview
php
<?php
/**
 * Assign default featured image
 *
 * @link https://wpforms.com/developers/how-to-set-a-default-featured-image-for-post-submissions/
 */
function wpf_dev_post_submissions_process( $post_id, $fields, $form_data ) {
    // If form ID is 463, run code below
    if ( 463 !== absint( $form_data[ 'id' ] ) ) {
        return;
    }
    // Assign image as the default featured image
    // Replace 2812 with the image attachment id
    $image_id = absint(2812);
    set_post_thumbnail($post_id,$image_id);
    }
add_action( 'wpforms_post_submissions_process', 'wpf_dev_post_submissions_process', 10, 3 );

Comments

Add a Comment