Forums

WordPress and relative URLs (7 posts)

  1. FRKT
    Member
    Posted 3 months 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
    Member
    Posted 3 months 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 3 months ago #

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

  4. songdogtech
    Member
    Posted 3 months 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
    Member
    Posted 3 months 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 3 months 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 3 months 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.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.