/ Published in: PHP

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
Copy this code and paste it in your HTML
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-&amp;gt;guid); echo $filename."<br/>\n"; $metadata = wp_generate_attachment_metadata($attachment->ID, $filename); wp_update_attachment_metadata($attachment->ID, $metadata); } }
URL: http://www.barattalo.it/wordpress/fix-pdf-preview-images-wordpress-4-7/
Comments
