Forums

<img src="<?php echo $pic; ?>" not working (6 posts)

  1. readme123456
    Member
    Posted 1 year ago #

    Hello, here's a question:
    On my website images are displayed with use of PHP like so
    <img src="<?php echo $media; ?>" alt="" width="940" height="600" />
    where
    $media = get_post_meta($post->ID, 'lead_image', true);

    However, some time ago it all start acting strange. Now the pictures get displayed together with a chunk of code, like
    [PICTURE] "alt="" width="940" height="600" />

    So, it seems, echo $media does not return a text string with the picture address, but rather displays the picture, and the remaining string gets treated as inside img src= ""

    It happens whenever there is any php inside img src.
    You can see it all at http://almasy-photography.com/

    Why is this happening and how to fix it?

    Thanks!

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    what gets filled into the custom field and how it this done?

    it seems that now, the whole code to show the image is in the custom field; probably this was not intended and was not always so.

    ((
    if you don't have two different ways of getting these images shown - just always the way you describe here - then the fix is to change the code from

    <img src="<?php echo $media; ?>" alt="" width="940" height="600" />

    to

    <?php echo $media; ?>

    ))

  3. readme123456
    Member
    Posted 1 year ago #

    It's a theme with a custom plugin, so, unfortunately it's not so simple.
    I've tried changing the output like you described, but it changes the wrapping href from pointing to corresponding post to simply a bigger picture. You can see what I mean at http://almasy-photography.com/archives/category/musicians - the thumbs are linked to posts, but if I do what you described, they suddenly have links to bigger photos.
    It's not easy to understand why, I guess.

  4. readme123456
    Member
    Posted 1 year ago #

    Maybe you can tell me how to pull the link from custom field and not the image it represents?

  5. readme123456
    Member
    Posted 1 year ago #

    It's interesting that in the Codex they seem to be using it in exactly the same way:

    <?php if ( get_post_meta($post->ID, 'thumb', true) ) : ?>
        <a href="<?php the_permalink() ?>" rel="bookmark">
            <img class="thumb" src="<?php echo get_post_meta($post->ID, 'thumb', true) ?>" alt="<?php the_title(); ?>" />
        </a>
    <?php endif; ?>
  6. readme123456
    Member
    Posted 1 year ago #

    I figured it out. The above mentioned plugin kept on feeding me the actual images specified in the custom fields, and not their urls.
    So, every time I wrote
    img src="<? echo $pic ?>"
    it was stuffing an image inside the img src.

    Thanks for your support!

Topic Closed

This topic has been closed to new replies.

About this Topic