• Well, somehow, I posted the following question with the screwed up Topic title “won’t work,” and I do apologize for that knuckle-headed mistake.

    I meant to say:
    <?php get_stylesheet_directory_uri(); ?> won’t work, but somehow the function code didn’t show up after I pushed the Post button.

    So, I’m posting the question again at the risk of gettin’ scolded.
    Any help anyone can offer will be truly appreciated.
    ==========================================================

    I have a wordpress site installed in a WAMP Server localhost environment on my machine.

    Right now, my links to images are hard-coded and work fine.

    I went to a wordpress group meeting tonight, and someone there showed me how to use this php function instead of doing all the hard-coding.

    <img src=”<?php echo get_stylesheet_directory_uri(); ?>/images/aternus.png” alt=”” width=”” height=”” />

    So, I plugged it in, made the appropriate path changes, tried every path configuration I could, and it won’t work—no image on the page.

    Somehow, it cannot find the path to my image folder. I’ve tried it several times, being careful to check every single character in the string, alas, no image on the page.

    Can someone please tell me what—if anything—I’m doin’ wrong?

    Thanks so much.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You need to use your browser inspector to see just what the locations are coming out as. If you are using firefox it would be firebug, each browser has an equivalent addon.
    Us it to see where your image locations are.
    Are you sure that your “images” directory is in your theme directory ? Theme support images belong here, content images usually are in a directory of “wp-content”

    Thread Starter adhdcelt

    (@adhdcelt)

    I know where my content images are located. Here:
    wamp/www/wordpress/wp-content/xxxxxx/xxxxxxx/xxxxxxxx/image.jpg.

    However, when I replace any part of the img src string that points to the image file, beginning with https://localhost, and then building on that each time by including another directory all the way to my image file, the image doesn’t show up. All I see is a tiny little icon, and when I mouse over it, I see the alt=”xxxxxx” text—just no image.

    If you are not getting your images displayed, then it is very likely (almost certain) that there is an error in the path. Suggest that you start with the basics of trying to display your “readme.html” file in your browser, this will be the base of where your “wp-content” and deeper image path starts. Once you thing you have worked it out, then try getting your browser to load the image directly.

    Thread Starter adhdcelt

    (@adhdcelt)

    There’s no problem with the image path. I have no problem displaying images on the site with hard-coded paths using the “img src” tag. Everything works fine. It’s only when I use the <?php echo get_stylesheet_directory_uri(); ?> function inside the “img src” thingy to point to the image folder path that they won’t display.

    For instance, this works just fine; beautiful site:
    <img src=”https://localhost/wordpress/wp-content/imagefolder1/imagefolder2/image1.jpg&gt;

    Any combination of this doesn’t:
    <img src=”<? php echo get_stylesheet_directory_uri(); ?>/imagefolder1/imagefolder2/image1.jpg>

    As simple as this seems, I MUST be doin’ something wrong—code doesn’t lie.

    Thanks so much for your most gracious input, RossMitchell.

    Any combination of this doesn’t:
    <img src=”<? php echo get_stylesheet_directory_uri(); ?>/imagefolder1/imagefolder2/image1.jpg>

    Please look at the directory path generated by this using firebug. What is the path it generates ? If you don’t answer this question I will not be able to help you.

    Thread Starter adhdcelt

    (@adhdcelt)

    I’ll get right on it.

    Thanks.

    Thread Starter adhdcelt

    (@adhdcelt)

    Alright, here we go.

    I looked at the path generated by this code in the page in question:

    <img src="https://localhost/wordpress/wp-content/imagefolder1/imagefolder2/imagefolder3/image1.png"/>

    It finds the image and displays it; no problem.
    ———————————————–

    I altered the hard code above with the php function to look like this:

    <img src="<? php echo get_stylesheet_directory_uri(); ?>/imagefolder1/imagefolder2/imagefolder3/image1.png"/>

    This doesn’t display the image, and the generated code in firebug looks like this everywhere I look:

    <img src="<? php echo get_stylesheet_directory_uri(); ?>/imagefolder1/imagefolder2/imagefolder3/image1.png"

    Hope this helps, and thanks again for your input, here.

    Thread Starter adhdcelt

    (@adhdcelt)

    UPDATE:

    Well, I have no idea how this happened, but it did, and I didn’t catch it when I put up the last post.

    This code, copied right out of firebug after I changed the hard code and added the php function and updated the page, and pasted it into the last reply,

    <img src="<? php echo get_stylesheet_directory_uri(); ?>/imagefolder1/imagefolder2/imagefolder3/image1.png"?>

    Showed up in the posted reply as this,

    <img src="<? php echo get_stylesheet_directory_uri(); ?>/imagefolder1/imagefolder2/imagefolder3/image1.png" as you can see in the last reply.

    I have no idea how that happened, since I copied it right out of firebug and pasted it into the reply and posted it.

    Not only that, I did this procedure again in the page, replacing the hard code with the php function, did all the updating, looked at the generated code in firebug, and walla, This is what I saw:

    <img src="<? php echo get_stylesheet_directory_uri(); ?>/imagefolder1/imagefolder2/imagefolder3/image1.png"/>

    None of the <? and ?> stuff at either end of the function this time. I’m now wondering why that is.

    Big clue I have been missing:

    Showed up in the posted reply as this,

    <img src=”<? php echo get_stylesheet_directory_uri(); ?>/imagefolder1/imagefolder2/imagefolder3/image1.png” as you can see in the last reply.

    The appearance of PHP code in your browser is a clear clue that your PHP syntax is wrong, the PHP is supposed to run in the server and give the results to your browser.
    When you sort this out you will be going in no time.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘My most sincere apology for a previous post.’ is closed to new replies.