Eğer kullanmakta olduğunuz tema “öne çıkan görsel” özelliğini destekliyorsa yazılarınıza tek tek öne çıkan görsel seçmeniz gerekebilir. Tabi opsiyonel bir özellik olduğundan kullanmaya da bilirsiniz ancak özellikle pek çok tema slider, archive gibi yapılarda bu görselleri kullanır.
Bu işi otomatik ve zahmetsiz olarak yapmanın basit bir yolu var. Aşağıdaki kod’u yeni bir php dosyası oluşturup içerisine yazmak suretiyle, wordpress sitenizin plugins dizinine yükleyip etkinleştirdiğiniz zaman. Yazılarınızda kullandığınız ilk resim otomatik olarak öne çıkarılacaktır.
/** * Plugin Name: Set featured image * Plugin URI: http://bueltge.de * Description: Set featureed image automaticly on save post/page * Version: 1.0.0 * Author: Frank Bültge * Author URI: http://bueltge.de * License: GPLv3 */
// This file is not called by WordPress. We don't like that.
! defined( 'ABSPATH' ) and exit;
if ( ! function_exists( 'fb_set_featured_image' ) ) { add_action( 'save_post', 'fb_set_featured_image' ); function fb_set_featured_image() { if ( ! isset( $GLOBALS['post']->ID ) ) return NULL; if ( has_post_thumbnail( get_the_ID() ) ) return NULL; $args = array( 'numberposts' => 1, 'order' => 'ASC', // DESC for the last image 'post_mime_type' => 'image', 'post_parent' => get_the_ID(), 'post_status' => NULL, 'post_type' => 'attachment' ); $attached_image = get_children( $args ); if ( $attached_image ) { foreach ( $attached_image as $attachment_id => $attachment ) set_post_thumbnail( get_the_ID(), $attachment_id ); } }
}