Can anyone please tell me how to add a custom PDF upload option in the POST and PAGE?
Please check the below image for more clarification.
There are several ways to add PDF upload for posts/page. The easiest is via ACF plugin:
- Install and activate "Advanced Custom Fields"
- Create a new custom field group and add a new field of type "File".
- Set the field label to "PDF File" and the field name to "pdf_file".
- In the "Return Value" section, choose "File URL".
- Under "Location," choose "Post Type" and then select "Page" and "Post."
- Switch to the "Presentation" tab and select the "Side" position. (this is necessary to display the field in the side side like a fetured image)
- Save the custom field group and go to the WordPress editor for a
post or page
- You should now see the "PDF File" custom field. Click the "Select File" button to upload a PDF file.
- Once the file is uploaded, you can use the custom field value in
your template code to display a download link or embed the PDF file.
Result:
Here is an example to display a link to pdf file in your page/post templates:
<?php if( !empty(get_field('pdf_file')) ): ?>
<a href="<?php echo get_field('pdf_file'); ?>"><?php echo __('Download PDF', 'your-domain'); ?></a>
<?php endif; ?>