I am trying to build a function, but without success!
function gen_thumb($post_ID){
$attachmentId = get_field( "file_upload", $post_ID);
generateThumbnail($attachmentId);
}
add_action( 'publish_post', 'gen_thumb');
Hi,
You can run the generation function manually using pdf_thumbnails_generate_attachment_metadata. E.g.
function gen_thumb($post_ID){
$attachmentId = get_field( "file_upload", $post_ID);
pdf_thumbnails_generate_attachment_metadata(null, $attachmentId);
}
add_action( 'publish_post', 'gen_thumb');
Note that this function is not part of the official PDF Thumbnails API so it may change in the future.
EDIT: Changed $post_ID
to attachmentId
in sample.
Thank you very much, are you able to tell me if the rest of my function is correct as I cannot seem to get it working.
Many thanks
Sorry, I should have used $attachmentId
in the sample, please see the updated sample above. Other than that, your function should be correct.
Heya – hope it’s ok that I’m jumping in here… I’m looking at trying out this plugin with ACF.
About the function you wrote above: is that just something I’d post into functions.php? or is there somewhere else I should be place it?
You can paste the code into functions.php and it should work. However, it would be better to do this from a plugin so that the functionality is separate from your theme. If you’d like to go with a plugin, you can follow the instructions in the plugin handbook.