WordPress.org

Ready to get started?Download WordPress

Ideas

Relative path for images/uploads?

  1. Luke Gedeon
    Member

    Tandem,

    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: 3 years ago #
  2. Tandem
    Member

    12345

    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.

    http://core.trac.wordpress.org/ticket/2682

    Posted: 3 years ago #
  3. Ron Mahon
    Member

    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
    Ron

    Posted: 3 years ago #
  4. ryanve
    Member

    12345

    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: 3 years ago #
  5. retlehs
    Member

    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: 3 years ago #
  6. xujunbocat
    Member

    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: 3 years ago #
  7. Rami Yushuvaev
    Member

    12345

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

    Posted: 3 years ago #
  8. safrick
    Member

    12345

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

    Posted: 3 years ago #
  9. Kim Gjerstad
    Member

    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:
    http://wordpress.org/extend/plugins/velvet-blues-update-urls/
    http://wordpress.org/extend/plugins/change-wp-url/

    Otherwise, find the simple mysql code to change your domain name in all links here:
    http://coding.smashingmagazine.com/2008/12/18/8-useful-wordpress-sql-hacks/

    Posted: 3 years ago #
  10. Tandem
    Member

    12345

    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: 3 years ago #

RSS feed for this topic

Reply »

You must log in to post.

  • Rating

    12345
    223 Votes
  • Status

    Duplicate of another idea