Forums

How do I make a relative image link? (14 posts)

  1. matty b
    Member
    Posted 1 year ago #

    Hey guys and gals,
    I can't seem to figure out how to make a site-relative image link into my images folder. I can only get the images to work using an absolute link that includes the entire url (http://. . .). This is a problem, since I'm developing new replacement sites in a different place than where the live site is currently (sometimes in a subfolder, sometimes in a completely different url). Once I make the replacement site live, I'm going to have to go into every page an change the image links since that url will no longer be valid.

    Basically, I want to reference the images folder relative to the pages, but I haven't been able to figure out the pathway.

    What am I missing? Please help this noob!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    Are you adding these images to the theme's template files?

  3. matty b
    Member
    Posted 1 year ago #

    Yep, I'm uploading them to the images folder in the template folder. If I need to put them somewhere else in the file structure I can.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    It's not where the images are. It's where/how you are adding the image code that we need to know. Are you adding the code to the template files themselves?

  5. matty b
    Member
    Posted 1 year ago #

    Sorry for the confusion. The answer is both in the page code (in the WP user interface) and in the template file (header image for example). I haven't been able to get either working from a relative link. Although, all my CSS background images work fine with just images/image.jpg.

    Thanks for your help btw.

  6. matty b
    Member
    Posted 1 year ago #

    While searching, I found your response to a nearly identical question (you're just all kinds of helpful).

    Is this what I should use?

    <img src="<?php bloginfo('template_directory'); ?>/images/banner_temp.jpg" />

  7. matty b
    Member
    Posted 1 year ago #

    Hmm, that worked for the header image, but not the images posted in the widget code (just using the "text" widget)

  8. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    That's why I needed to now where you were adding this image markup. As soon as you move outside of the templates, you simply have to use absolute urls because of the way in which WP works and constructs its permalinks. why not try adding the images to the sidebar template file instead of a text widget? That way, they be far more portable across multiple sites.

  9. matty b
    Member
    Posted 1 year ago #

    I need the images in the sidebar to be editable by the client through the WP UI, so no putting them in the sidebar.php file. My client is adding her own content and pics to the pages, so I need to let her know how to do it properly in a way that will be portable.

    If I have to go in an change that widget code when the site goes live it's not the end of the world. However, I am concerned about all the images in the pages. That would be a PITA.

    So, there's no way to make a relative link in the page HTML? How do people develop WordPress sites before they go live? Change all the image code twice?

  10. matty b
    Member
    Posted 1 year ago #

    After thinking about it, she could edit the sidebar.php in the UI's editor, but the pages are still a problem.

  11. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    So, there's no way to make a relative link in the page HTML?

    Not reliably, no. I've seen some pretty ugly relative fudges but I'd never trust them to work 100% of the time.

    How do people develop WordPress sites before they go live?

    In this situation, I'd probably be looking at developing custom widgets and/or passing image urls through via a theme options page.

  12. matty b
    Member
    Posted 1 year ago #

    Not reliably, no. I've seen some pretty ugly relative fudges but I'd never trust them to work 100% of the time.

    Forgive me for being frank, but that sucks (who's frank anyway). Thanks for clearing that up though.

    In this situation, I'd probably be looking at developing custom widgets and/or passing image urls through via a theme options page.

    Admittedly, you've lost me here. If you have the time to explain, I'm interested. If not, no worries.

    Would a Find-n-Replace plugin work? (just before or after going live?)

  13. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    Forgive me for being frank, but that sucks

    Agreed. There has been talk of an overhaul of the entire permalink system because of problems like this but it would be a pretty daunting task, so don't expect any changes soon.

    If you have the time to explain, I'm interested.

    You're in luck! Chip Bennet has just published a very comprehensive tutorial on this very subject:
    http://www.chipbennett.net/2011/02/17/incorporating-the-settings-api-in-wordpress-themes/

    Would a Find-n-Replace plugin work? (just before or after going live?)

    That might well work for widgets etc. See http://wordpress.org/extend/plugins/search-and-replace/

  14. matty b
    Member
    Posted 1 year ago #

    Thanks for the links!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags