Support » Fixing WordPress » WordPress and relative URLs

  • Hello,

    I’m developing a website that is subject to be moved several times. As such, I’d like to connect images associated with WordPress “links” using relative URLs. Unfortunately the software seems to insist on prefixing any URL with http:// lest I do so myself, effectively breaking them by making them absolute.

    Any ideas?

    All the best,
    Johannes

Viewing 7 replies - 1 through 7 (of 7 total)
  • WordPress doesn’t handle relative urls at all well, so I’d suggest avoid them whenever possible. with regard to the image insertion, the only way to fix these urls is by editing them manually, as you appear to be doing at the moment.

    Really? That’s a disaster! Thanks for your reply.

    You can also use Search Regex to find and replace URLs in posts and pages. And, I always use something like

    <?php bloginfo('url'); ?>/wp-content/themes/default/images/myimage.jpg

    to construct an image URL that will “survive” a move.

    <?php bloginfo('url'); ?> won’t work if used within the post/page content, though.

    http://wordpress.org/extend/plugins/search-and-replace/

    is another good plugin if you need to make mass changes.

    For the record, I’ve developed WordPress sites that have been moved and changed not only servers, but domain names as well – there’s no need to hard-code anything.

    If you use the uploader for you images within posts, then their URL is coded in the database. When the site is moved and the settings are changed, the URL will change along with them.

    if you’re talking about theme files, all you have o do is use <?php bloginfo('template_directory');?> to provide a path to the theme files (if the image are housed in the theme files), or use <?php bloginfo('home'); ?> to pull in the main URL (you can add to that manually if the images aren’t in the theme files.)

    This is what I do every time, and I’ve never had an issue with moving anything.

    Forgot to add that, yes, you need to be able to run PHP in posts/pages to use images URLs and links like:

    <?php bloginfo('url'); ?>/wp-content/themes/default/images/myimage.jpg

    and I can leave that structure in place to use code chunks in different themes and sites without having to change it.

    I don’t use the WP image uploaders as they require directory permissions to be more writeable than FTP.

    As I have stated here:
    http://wordpress.org/support/topic/279385?replies=7#post-1405148

    There is a perfectly reasonable solution to this problem. All that remains is for someone to implement it.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘WordPress and relative URLs’ is closed to new replies.