Membuat Featured Image Otomatis Di Setiap Post WordPress

Auto featured image wordpress

Kalo kamu baca ini pasti lagi bingung cara membuat Featured Image di WordPress secara otomatis ya? Atau kelupaan ada beberapa post di blog kamu yang tidak menggunakan Featured Image?

Langsung saja salin PHP code dibawah ini ke file functions.php di tema WordPress kamu. Taruh aja paling bawah.

//featured image
function autoset_featured() {
          global $post;
          $already_has_thumb = has_post_thumbnail($post->ID);
              if (!$already_has_thumb)  {
              $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
                          if ($attached_image) {
                                foreach ($attached_image as $attachment_id => $attachment) {
                                set_post_thumbnail($post->ID, $attachment_id);
                                }
                           }
                        }
      }
add_action('the_post', 'autoset_featured');
add_action('save_post', 'autoset_featured');
add_action('draft_to_publish', 'autoset_featured');
add_action('new_to_publish', 'autoset_featured');
add_action('pending_to_publish', 'autoset_featured');
add_action('future_to_publish', 'autoset_featured');

Silahkan kamu cek apakah tiap post sudah ada featured image atau belum? Jika sukses atau ada masalah tanyakan di komentar ya.

4 Comments

  1. cahyo

    ayuk mampir kesini ya D.8.E.B.7.E.6.B ada banyak kejutan setiap harinya

  2. cahyo

    membuat-featured-images-otomatis-disetiap-post-wordpressP0K3RV1TA D.8.E.B.7.E.6.B

  3. DheVilz

    lagi nyari tips ini, semoga bisa. mau praktek

Leave a Reply