File upload input use Pretty Permalinks
Version
- Carbon Fields: 2.2.0
- WordPress: 4.9.6
- PHP: 7.1
Container definition
Carbon function used:
Field::make( 'file', 'crb_pub_url', 'Files' )
->set_value_type( url' )
->set_help_text( 'Example: pdf, doc, docx, txt' )
<a class="download-btn" title="<?php echo carbon_get_the_post_meta( 'crb_pub_url' ); ?>" href="<?php echo carbon_get_the_post_meta( 'crb_pub_url' ); ?>">
<i class="fas fa-cloud-download-alt fa-2x" aria-hidden="true"></i>
</a>
Comments
Using the File input, how would I go about making a pretty link to the download file rather than wp-content/uploads/2018/06/1-s2.0-S2095268617303476-main.pdf but publications/sample-pub/1-s2.0-S2095268617303476-main.pdf.
Hi @breath-ee,
Thank you for your feedback.
This is the default WordPress behavior and you can't use custom (pretty) permalinks with the file field at the moment.
You can change the default uploads directory by adding the following in your wp-config.php file
define('UPLOADS', 'custom-uploads-directory');
Unfortunately, this will break the URLs of your current uploads.
The other option is to use something like https://github.com/mattheu/Private-Media -- i.e. to proxy the attachments through PHP without exposing the actual location of the file.
@deqngeorgiev, thanks for the reply. Understood, that's a shame it's not available in the core. I don't want to change the uploads path for those reasons you state. The plugin link is a good idea for a private uploads but this is for public file. I just wanted to prettify the path wp-content/uploads/2018/06/1-s2.0-S2095268617303476-main.pdf to publications/sample-pub/1-s2.0-S2095268617303476-main.pdf. I'll have to have a dig around, maybe a function to hook into carbonfields. I'm sure there is something just requires a bit more looking.
Hey @breath-ee,
I'm closing this issue because there is not much to do here. If you have any ideas or want to discuss something feel free to reopen the issue.