Forums

WordPress and relative URLs (8 posts)

  1. FRKT
    Member
    Posted 2 years ago #

    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

  2. esmi
    Theme Diva & Mod
    Posted 2 years ago #

    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.

  3. FRKT
    Member
    Posted 2 years ago #

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

  4. songdogtech
    Member
    Posted 2 years ago #

    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.

  5. esmi
    Theme Diva & Mod
    Posted 2 years ago #

    <?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.

  6. doodlebee
    Member
    Posted 2 years ago #

    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.

  7. songdogtech
    Member
    Posted 2 years ago #

    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.

  8. thanatica2
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.