Relative path for images/uploads?

  1. Luke Gedeon


    I am glad to have your support for the idea of relative paths. Maybe with enough requests we can get the critical mass needed to sway some opinions.

    I should mention however that this is not quite as simple as it seems, and many other CMS have had to wrestle with this too.

    Relative references do have a down side too, we just have to decide which method is the most helpful to the most people.

    Posted: 6 years ago #
  2. Tandem


    Any ideas why this is still an issue with the latest WP release?
    I just came across a ticket in the WordPress tracker labeled 'Paths should be relative for images and uploads'. The ticket has been closed and marked as fixed 2 years ago.


    Posted: 6 years ago #
  3. Ron Mahon

    The other side of that problem is it depends on how many graphics your site will have during its lifetime.

    All operating systems have a file limit to every directory. So depending on your operating system there is a finite number of graphics that can be stored in one directory.

    One way around that which may work and it seems I used it in Drupal or somewhere in the past. It is to have a graphics/images directory,with nothing in the root of that directory except system graphics. and then subdirectories within that graphic/image directory for other parts of your site which a help avoid the directory limit.

    Or perhaps for WordPerfect a better solution would be to leave the graphics for the system where they are in the theme directory and move this new directory somewhere else. Perhaps in the plug-in directory, or even the wp_content/images.

    This would make the path much shorter and would not be affected by changes to the theme. so the path would be/wp_content/images/sub1 etc.

    Anyway I'm still new to WordPress somebody is probably much more qualified than I am.
    Best regards

    Posted: 6 years ago #
  4. ryanve


    I agree relative paths seem better for uploads. If you transfer from one domain to another though WordPress handles this properly if you check download attachments.

    But maybe some kind of shortcode [imgdir] could also work (although it would have to work within the [caption] shortcode).

    Posted: 6 years ago #
  5. retlehs

    I released a theme called Roots Theme a few months ago, one of the big features is root relative URLs for pretty much everything.

    See roots-cleanup.php:

    function roots_root_relative_url($input) {
    	preg_match('/(https?:\/\/[^\/|"]+)/', $input, $matches);
      // make sure we aren't making external links relative
      if (isset($matches[0]) && strpos($matches[0], site_url()) === false) {
        return $input;
      } else {
        return str_replace(end($matches), '', $input);
    add_filter('bloginfo_url', 'roots_root_relative_url');
    add_filter('theme_root_uri', 'roots_root_relative_url');
    add_filter('stylesheet_directory_uri', 'roots_root_relative_url');
    add_filter('template_directory_uri', 'roots_root_relative_url');
    add_filter('the_permalink', 'roots_root_relative_url');
    add_filter('wp_list_pages', 'roots_root_relative_url');
    add_filter('wp_list_categories', 'roots_root_relative_url');
    add_filter('wp_nav_menu', 'roots_root_relative_url');
    add_filter('wp_get_attachment_url', 'roots_root_relative_url');
    add_filter('wp_get_attachment_link', 'roots_root_relative_url');
    add_filter('the_content_more_link', 'roots_root_relative_url');
    add_filter('the_tags', 'roots_root_relative_url');
    add_filter('get_pagenum_link', 'roots_root_relative_url');
    add_filter('get_comment_link', 'roots_root_relative_url');
    add_filter('month_link', 'roots_root_relative_url');
    add_filter('day_link', 'roots_root_relative_url');
    add_filter('year_link', 'roots_root_relative_url');
    add_filter('tag_link', 'roots_root_relative_url');
    add_filter('the_author_posts_link', 'roots_root_relative_url');
    // Leaving plugins_url alone in admin to avoid potential issues (such as Gravity Forms)
    if (!is_admin()) {
      add_filter('plugins_url', 'roots_root_relative_url');
    // remove root relative URLs on any attachments in the feed
    function roots_relative_feed_urls() {
    	global $wp_query;
    	if (is_feed()) {
    		remove_filter('wp_get_attachment_url', 'roots_root_relative_url');
    		remove_filter('wp_get_attachment_link', 'roots_root_relative_url');
    add_action('pre_get_posts', 'roots_relative_feed_urls' );
    Posted: 6 years ago #
  6. xujunbocat

    When you moved your blog from xxx.com to a different domain xxx.net, You need to export database file xxx.sql, then open it and replace xxx.com to xxx.net, you can import the new xxx.sql, all the data works fine.

    Posted: 6 years ago #
  7. Rami Yushuvaev


    xujunbocat, we dont want to do this, we want wordpress to do this for us automaticly.

    Posted: 6 years ago #
  8. safrick


    Relative paths would make it much easier to work with development, staging and production environments.

    Posted: 6 years ago #
  9. Kim Gjerstad

    WordPress.org will never allow this simply because relative links are useless for RSS and their derivatives (ie, email alerts with Feedburner).

    If you need to migrate, there's 2 plugins for that:

    Otherwise, find the simple mysql code to change your domain name in all links here:

    Posted: 6 years ago #
  10. Tandem


    You can use root relative URLs and still generate RSS with functional links. It is up to the feed file generator to make sure all links either are written using fully qualified URL or take advantage of the XML:Base attribute to resolve relative links. Even your own site uses root relative URLs.

    Posted: 6 years ago #

RSS feed for this topic

Reply »

You must log in to post.

  • Rating

    223 Votes
  • Status

    Duplicate of another idea