تصویر شاخص

جلوگیری از انتشار مطالب بدون تصویر شاخص در وردپرس

تصویر شاخص در سایت یکی از عوامل زیبا شدن و جلب توجه محسوب میشود و اامی کردن آن باعث می شود تا باعث جلوگیری از انتشار مطالب بدون تصویر شاخص می شود.

در این مطلب آموزشی قصد داریم تا قطعه کدی را به شما معرفی کنیم تا باعث شود تا از انتشار مطالب بدون عکس جلوگیری شود.

برای دست یافتن به این امر کافی است تا قطعه کد زیر را وارد فایل functions.php کنیم:

 

add_action('save_post', 'wpds_check_thumbnail');
add_action('admin_notices', 'wpds_thumbnail_error');
function wpds_check_thumbnail($post_id) {
    // change to any custom post type
    if(get_post_type($post_id) != 'post')
        return;
    if ( !has_post_thumbnail( $post_id ) ) {
        // set a transient to show the users an admin message
        set_transient( "has_post_thumbnail", "no" );
        // unhook this function so it doesn't loop infinitely
        remove_action('save_post', 'wpds_check_thumbnail');
        // update the post set it to draft
        wp_update_post(array('ID' => $post_id, 'post_status' => 'draft'));
        add_action('save_post', 'wpds_check_thumbnail');
    } else {
        delete_transient( "has_post_thumbnail" );
    }
}
function wpds_thumbnail_error()
{
    // check if the transient is set, and display the error message
    if ( get_transient( "has_post_thumbnail" ) == "no" ) {
        echo "قاب رویت نیست";
        delete_transient( "has_post_thumbnail" );
    }
}

 

جلوگیری از انتشار مطالب بدون تصویر شاخص در وردپرس

کد مطالب مرتبط بر اساس دسته بندی بدون افزونه در وردپرس

فارسی کردن اعداد در وردپرس

post ,thumbnail ,transient ,wpds ,id ,has ,has post ,post thumbnail ,check thumbnail ,transient has ,wpds check ,wpds check thumbnail ,wpds thumbnail error

مشخصات

تبلیغات

آخرین ارسال ها

برترین جستجو ها

آخرین جستجو ها

Web specialists برق و مدیریت قهوه گانودرما درمان لاغری شهیدستان کرج CorelDRAW لوله بازکنی تهران محتوای باماگرد دادامووی | DadaMovie فیروزه ی جان فروشگاه جویا