Search code examples
wordpresswordpress-shortcodewordpress-hook

Wordpress PDF upload option like feture image


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.

enter image description here


Solution

  • There are several ways to add PDF upload for posts/page. The easiest is via ACF plugin:

    1. Install and activate "Advanced Custom Fields"
    2. Create a new custom field group and add a new field of type "File".
    3. Set the field label to "PDF File" and the field name to "pdf_file".
    4. In the "Return Value" section, choose "File URL".
    5. Under "Location," choose "Post Type" and then select "Page" and "Post."
    6. 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)
    7. Save the custom field group and go to the WordPress editor for a post or page
    8. You should now see the "PDF File" custom field. Click the "Select File" button to upload a PDF file.
    9. 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: enter image description here

    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; ?>