• Resolved francistan77

    (@francistan77)


    Hi

    Is it possible to change the upload directory of the testimonial, currently its going to uploads folder and I don’t want it there, thanks in advance

Viewing 4 replies - 1 through 4 (of 4 total)
  • anonymized-13171256

    (@anonymized-13171256)

    Add this to your theme’s functions.php or create an mu-plugin:

    /**
     * Custom upload directory for Strong Testimonials
     *
     * @param array $uploads
     *
     * @return array
     */
    function my_testimonials_upload_dir( $uploads ) {
    	if ( isset( $_REQUEST['wpmtst_submit_testimonial'] ) ) {
    		$uploads['path'] .= '/testimonials';
    		$uploads['subdir'] = 'testimonials';
    	}
    
    	return $uploads;
    }
    add_filter( 'upload_dir', 'my_testimonials_upload_dir' );
    anonymized-13171256

    (@anonymized-13171256)

    This code works for both the post editor and the front-end form.

    /**
     * Custom upload directory for Strong Testimonials
     *
     * @param array $uploads
     *
     * @return array
     */
    function my_testimonials_upload_dir( $uploads ) {
    	// In the post editor or through the front-end form
    	if ( ( isset( $_REQUEST['post_id'] ) && 'wpm-testimonial' == get_post_type( $_REQUEST['post_id'] ) )
    		|| isset( $_REQUEST['wpmtst_submit_testimonial'] ) )
    	{
    		$uploads['path'] .= '/testimonials';
    		$uploads['subdir'] = 'testimonials';
    	}
    
    	return $uploads;
    }
    add_filter( 'upload_dir', 'my_testimonials_upload_dir' );
    Thread Starter francistan77

    (@francistan77)

    Hi Chris, thank you this works well but the “uploads/2017/05/testimonials” directory is inside the current year folder in uploads, can it be “uploads/testimonials”

    anonymized-13171256

    (@anonymized-13171256)

    Sorry about that. I have not used the month/year option in so long, I did not consider that.

    <?php
    /**
     * Custom upload directory for Strong Testimonials
     *
     * @param array $uploads
     *
     * @return array
     */
    function my_testimonials_upload_dir( $uploads ) {
    	// In the post editor or through the front-end form
    	if ( ( isset( $_REQUEST['post_id'] ) && 'wpm-testimonial' == get_post_type( $_REQUEST['post_id'] ) )
    		|| isset( $_REQUEST['wpmtst_submit_testimonial'] ) )
    	{
    		$uploads['subdir'] = '/testimonials';
    		$uploads['path']   = $uploads['basedir'] . $uploads['subdir'];
    		$uploads['url']    = $uploads['baseurl'] . $uploads['subdir'];
    	}
    
    	return $uploads;
    }
    add_filter( 'upload_dir', 'my_testimonials_upload_dir' );
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Changing Upload file location’ is closed to new replies.