WordPress.org

Forums

Media file URL on parent page (2 posts)

  1. WordpMoon12
    Member
    Posted 1 year ago #

    Is there anyway to change the media file path for the PDF files that I upload for each page.

    At the moment if I upload a file to my WordPress page, the URL of the PDF will have a path: http://mywebsite.com/wp-content/uploads/document.pdf

    instead, I would like the PDF URL have a relative path to the page where I uploaded it.
    e.g. http://mywebsite.com/mypage/document.pdf

    Any ideas, is this possible to do on WordPress?

  2. catacaustic
    very awesome
    Posted 1 year ago #

    It's not possible out of the box. The reason for this is that your pages URL is dynamic and doesn't actually exist, so there's no easy way to reference anything past that.

    The two ways that come to mind now are either easy, or hard.

    The wasy way...

    Install a 301-redirect plugin and use that to redirect from http://www.site.com/mypage/mypdf to http://www.site.com/wp-content/uploads/2014/7/my.pdf

    The hard way...

    Create your own plugin and use the rewriting and URL hooks to determine if there's a valid file attached to the requested page if there's a 404 Not Found page requested. It's a whole lot more work, but it's possible to do if you spend the time looking at it.

Topic Closed

This topic has been closed to new replies.

About this Topic