Home » blog seo friendly » Membuat Featured Image Otomatis Di Setiap Post WordPress

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

    May 27, 2017 at 2:41 am

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

    Reply
  2. cahyo

    June 6, 2017 at 3:46 am

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

    Reply
  3. Pegasus Cozza

    July 14, 2017 at 2:18 am

    ijin nyoba omm

    Reply
  4. DheVilz

    November 18, 2018 at 10:20 pm

    lagi nyari tips ini, semoga bisa. mau praktek

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *