3. Adding and importing documents
The Document Library Pro plugin provides 4 ways to add documents:
- Add documents manually
- Upload files direct to Media Library
- Bulk import documents
- Upload documents from the front end
We also have a separate tutorial on how to allow people to add documents from the front end of your website.
Add documents manually
The process for adding a document is similar to creating a page or post in WordPress:
- Go to Document Library → Add New.
- Complete all the fields of information that you wish to display about your documents:
- Title (required) - The title of the document.
- Content (optional) - Use this field for a description of the document, or to add the full content of the document if you want it to be available online without having to download it. Supports all standard WordPress formatting options, shortcodes and embedded audio/video players.
- Excerpt (optional) - Add a brief summary of the document.
- Author - The username of the user who created the document. You can change this to any other user instead.
- Document Link (optional) - Upload a file or add a URL where the document is located. Choose from 3 link options:
- None - Use this if you have added the full document to the content field, and do not wish to link to a downloadable file or another URL.
- File Upload - Use the ‘Add Media’ button to upload a file. This will be attached to the document as a downloadable file.
- Custom URL - If you wish to link to a separate web page on your website or any third party site, then enter the full URL here. For example: https://google.com
- Document Categories (optional) - Create categories for your documents. Note: These are separate from post categories and will only be used for your documents.
- Document Tags (optional) - Use tags to make your documents easier to find. Note: These are separate from post categories and will only be used for your documents.
- File size - If you have uploaded a document directly then this will be greyed out and calculated automatically. If you are linking to a third party URL from the 'Document Link' field then you can enter the file size manually, for example if you are linking to a file that is hosted on Dropbox. Enter the file size in any format you like, e.g 2.5MB.
- Featured image (optional) - Upload an image if you wish to include an image column in the document library.
- If you have added custom fields or taxonomies to the documents post type then these will appear too. (Learn how here.)
Whichever fields you complete will appear on the single document page. You can also include any or all of these fields as columns on the main document library page.
If any of the above fields are missing and you wish to use them, then please make sure they are enabled on the settings page.
Direct file upload
You can use drag and drop to upload one or more files directly to the WordPress Media Library:
- Go to Documents → Import.
- Go to the 'Drag and drop file upload' section.
- Drag and drop one or more files within the dotted lines, and wait for them to upload.
Note: You can only upload file types that are supported by your WordPress installation.
Once uploaded, the following will happen for each file:
- A document post will be created, which you can find on the main Document Library page in the WordPress admin. The filename will be used to create the document title, so we recommend giving each file a suitable name before uploading it. You can then edit each document to add extra information, as required.
- When the document name is created, it will be the same as the filename, but the file extension, spaces, dashes and hyphens are removed. The case and spaces in the filename are preserved, and dashes are replaced with spaces.
- The file will be tagged as a 'Document' within the Media Library so that you can use the 'Type' dropdown to view document files only.
Bulk import documents
If you wish to bulk import documents with additional information about each one, then you can import them from a CSV file:
a. Add your document fields
First, you need to make sure that your document library is set up with all the fields that you will be importing. You can do this by enabling the relevant fields on the settings page and by creating any additional custom fields that you require.
b. Prepare the CSV file
Next, you should create a CSV file containing all the data about each document. You can do this using any spreadsheet software such as Microsoft Excel, iOS Pages, or Google Sheets - create the file and use the 'Save As' option to select the .csv file type.
Each document library field should be stored as a column in the CSV file. Add each document as a separate row in the CSV file, and include a header row.
It is essential that the format of your CSV file is correct. Some tips:
- Download our sample CSV file (right-click and save it to your computer) and open it in a spreadsheet program such as Excel. The sample CSV assumes that you are using all the default fields, plus 2 custom fields. You should edit the columns to delete any you don't need, and add any additional custom fields. Also delete the sample documents from our CSV file (rows 2-4) - these are simply intended to show you how to format the data for each field type. It's fine to import the same documents if you like, but remember to delete them before launching your finished document library! All fields apart from 'title' are optional:
- Name - This is the name of the document and will appear in the 'title' column of the document library and at the top of the single document page.
- Categories - The names of your document categories (not the slugs). If the categories already exist on your website then the documents will be added to the existing categories, otherwise new categories will be created. Use > to indicate parent/child category structures, as shown in row 2 of the sample CSV. (Note: When you specify parent/child categories, the document will be added to the child category but not the parent.)Due to how CSV files work, if you are listing multiple categories within the same cell then you need to present it using either of these methods:
- Enclose the list of categories within the cell with double quotes (e.g. "articles, resources").
,instead of a true comma (e.g. "articles , resources").
- Tags - Enter the names of your document tags (not the slugs). If the categories already exist on your website then the documents will be added to the existing tags, otherwise new categories will be created.
- File URL - If you want to upload the document file directly to your Media Library then enter its URL here. The URL must link to the file itself and not a webpage, e.g. https://www.website.com/my-file.pdf.
- Direct URL - Enter a URL here (e.g. https://google.com) if you want to link to a document in a third party location, instead of uploading it directly to your Media Library - for example, if the document is a YouTube video then you would add the YouTube link here.
- Featured Image URL - If you want to include an image of each document (either in the 'image' column of the document library or on the single document page) then add the URL of its current location here. It will then be uploaded to the Media Library and set as the featured image for the document.
- File Size - You only need to import the file sizes if you are linking to externally hosted documents, e.g. on Dropbox. If you are uploading documents directly to the Media Library then the file size will be calculated automatically.
- Excerpt - Enter text or HTML if you wish to include a document excerpt.
- Content - Enter text or HTML if you wish to include more in-depth content for the document. This might be a longer description or the full content of the document.
- Published - Enter 'TRUE' to publish the document as soon as it is uploaded; or 'FALSE' if you wish to save it as a draft so that you can make any changes before publishing it manually.
- cf: If you have created custom fields for your documents then you should add each one as a separate column, as in the sample CSV. Add cf: before the custom field name in the header row.
- tax: If you have created custom taxonomies for your documents then you should add each one as a separate column, as in the sample CSV. Add tax: before the custom taxonomy name/slug or label in the header row.
- Create a test CSV file containing 1 document and upload this first, as a test. You can then repeat the test until you are happy with the results, before doing the full upload.
Note: It doesn't matter whether the column headers in the CSV file are the same as the field names in your document library, as you will match them up as part of the import.
c. Upload the CSV file
- Go to Document Library → Import.
- Go to the 'CSV upload' section and click 'Import CSV'.
- On the 'Import documents from a CSV file' page, use the 'Choose file' button to select the CSV file and click 'Continue'.
- On the 'Map CSV fields to documents' page, match each of the columns from the CSV file to the fields that are used for the document custom post type. This ensures that the data is imported to the correct document library fields. Document Library Pro will try to do this automatically based on the header row of your CSV file, and you can manually change the selections as needed.
- Click 'Run the importer'.
- This will import the documents and attached files to your WordPress site. You will then see a success message with a link to edit the documents.
Upload documents from the front end
Document Library Pro also comes with a shortcode which you can use to insert a 'Submit document' form anywhere on your website. To add the form, simply create a page and add the shortode:
The form will contain all the fields which are enabled for your documents, such as the title, excerpt, author, and so on.
Moderating new document submissions
We recommend enabling moderation for new document submissions unless you can absolutely trust the people who are submitting the documents. This holds new documents for approval by an administrator before they are added to the document library. The administrator receives an email notifying them that a document has been added which needs approval.
Protecting the document submission page
By default, the page containing the 'Upload document' form will be public so that anyone can submit a document.
To make the form more secure, it contains an anti-spam honeypot to stop bot submissions. The developer documentation also contains filters which you can use to limit the maximum size of files which can be uploaded through the form.
For security reasons, we strongly recommend restricting access to the page containing the form so that only pre-approved people can add documents. This is because as with any type of online form, Document Library Pro can't control what file type the user adds to the 'Custom URL' field or what they link to, and it also can't scan the uploaded documents for viruses.
If you want the form to be public then you should always enable moderation. That way, you can check that each submission is legitimate and test for any problems before the document is added to the library.
How to edit or translate the emails
Document Library Pro sends an email to the administrator (as set in Settings → General) whenever a new document is added via the front end form. You can use string translation edit the content of the email or translate it into another language. For details, please see the article on translating Document Library Pro.
What about files already in the Media Library?
If your document files (e.g. PDF's) are already in the WordPress Media Library then you need to convert them into documents in order to display them in the document library. You can do this as follows:
- Go to Media in the WordPress admin.
- Use the icon above the list of media files to make sure you are viewing the Media Library as a list rather than a grid.
- Select the files that you wish to display in the document library.
- Open the 'Bulk actions' dropdown above the list of files, and select 'Add to document library'.
- You will see a success message with a link to edit the newly created document post, which will appear in your document library. You can use this page to add further information about each document via the Documents section of the WordPress admin. If you don't add further information then the filename will appear in the total column of the document library, and users will be able to click to download the file.
Can I upload documents using FTP?
Yes, although this is less straightforward than simply using drag and drop method which is built into Document Library Pro. That's because FTP only adds the documents to your website's file system and not the database, and they need to be in the database in order to appear in the document library.
Use the following instructions to overcome this issue and add documents via FTP:
- First, add the document files to the uploads directory where your Media Library files are stored (.../wp-content/uploads/). For more details, see WPBeginner's article about How to Bulk Upload WordPress Media Files using FTP.
- Next, use the free Add from Server plugin to detect or make them visible. (Note: This plugin is no longer supported by the original developer, but we have had other customers use it successfully. We recommend deleting it after uploading your documents.)
- Finally, convert the files into Documents so that they can be displayed in the document library.
How can I update and replace documents?
Please see our separate article for advice about updating your documents in future.
Display your documents
Now you've added some documents, it's time to start displaying them on your website.