Make media URL for images pretty WordPress

When I upload a file it hosts it at /app/uploads/2016/02/placeholder1.jpg, i’ve been looking but can’t find anything.

If I want to host some PDF files, how do I change the path above for certain files only? As in, any file I upload will be hosted there as norm. But if I want to separately host a PDF to show someone, how can I change the url so it’s like /downloads/test.pdf/?

Read More

I can’t find any plugins for this either.

Thank you.

Related posts

1 comment

  1. By default all images or .pdf files are uploaded to wp-content/uploads/ folder when you upload via media library from admin.
    If you want to upload .pdf files to specific folder, follow steps.

    1) Create downloads (or any other name you want) in uploads directory.

    2) Make sure to give 777 permission to downloads folder.

    3) Use filter, add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' ); to upload pdf files.

    4) Using wp_handle_upload_prefilter filter, you can change the path of the pdf files to upload in custom_upload_filter function.

    add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );
    function custom_upload_filter( $file ){
        // Check if file extension is .pdf,and upload pdf file into downloads folder
        return $file;
    }
    

    For Details : https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_handle_upload_prefilter

Comments are closed.