enflasyonemeklilikötvdövizakpchpmhp
DOLAR
44,8573
EURO
52,8184
ALTIN
6.966,26
BIST
14.587,93

WordPress otomatik öne çıkan görsel kodu

WordPress otomatik öne çıkan görsel kodu
14.09.2022
4
A+
A-
WordPress autoset featured image kodu

WordPress otomatik öne çıkan görsel kodu : WordPress sitelerinizde içeriğe eklenen ilk görseli featured image ve anasayfada thumbnail olarak ayarlamanıza yarayan kod ile birlikte eklentisiz bir şekilde bu sorunu çözebilirsiniz.

Bu işlemi yaptığınızda yazı içerisine eklenen resimler otomatik olarak featured image olarak ayarlanıp anasayfada ise ilgili yazının küçük resmi (thumbnail) olur.

Bu kodu functions.php sayfasının en alt kısmına eklemeniz gerekmektedir.

// Auto add featured image
function wpsites_auto_set_featured_image() {
   global $post;
   $featured_image_exists = has_post_thumbnail($post->ID);
      if (!$featured_image_exists)  {
         $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', 'wpsites_auto_set_featured_image');
Yorumlar

Henüz yorum yapılmamış. İlk yorumu yukarıdaki form aracılığıyla siz yapabilirsiniz.