/ Published in: PHP

URL: http://www.barattalo.it/wordpress/fix-pdf-preview-images-wordpress-4-7/
From WordPress 4.7 when you upload a PDF it generates jpg previews. All pdf will remain without previews, or you can use this script to generate previews.
Expand |
Embed | Plain Text
include 'wp-load.php'; include 'wp-admin/includes/image.php'; $attachments = $wpdb->get_results("select * from wp_posts where post_mime_type='application/pdf'"); if ($attachments) { foreach ($attachments as $attachment) { $filename = str_replace("http://".$_SERVER['HTTP_HOST'], $_SERVER['DOCUMENT_ROOT'], $attachment->guid); $metadata = wp_generate_attachment_metadata($attachment->ID, $filename); wp_update_attachment_metadata($attachment->ID, $metadata); } }
You need to login to post a comment.