Move plugin upload folder from mywebsite.com/wp-content/uploads/pdfuploads to mywebsite.com/pdfs?

I’m currently using a plugin that generates a PDF for customers but the URL is way too long. For eg – https://www.mywebsite.com/wp-content/uploads/pdfuploads/666666.pdf. Here’s the specific code from the plugin relating to this:

$upload = wp_upload_dir();
$upload_dir = $upload[‘basedir’];
$upload_dir = $upload_dir . ‘/pdfuploads’;
if (! is_dir($upload_dir)) {
mkdir( $upload_dir, 0755 );
$file = fopen($upload_dir.’/index.html’,”wb”);
echo fwrite($file,”Silence is golden.”);
fclose($file);
}

The PDF then generates in:

=> get_home_url().’/wp-content/uploads/pdfuploads/’
$attachments[0] = $upload_dir.’/pdfuploads/’

I want to shorten this URL so it reads something like – https://www.mywebsite.com/pdfs/666666.pdf. I tried adding RewriteRule ^wp-content/uploads/pdfuploads/(.*)$ /pdfs/$1 [R=301,NC,L] to htaccess but that didn’t move the files over. Is there a quick fix for this via htaccess or functions? Otherwise, if I need to edit the plugin’s PHP files myself, what do I need to change in the above code?

Read more here:: Move plugin upload folder from mywebsite.com/wp-content/uploads/pdfuploads to mywebsite.com/pdfs?

Leave a Reply

Your email address will not be published. Required fields are marked *