How to add images to a wordpress theme when working on MAMP?

I am new to MAMP and I am developing a theme I designed. However I can’t seem to get the images to render. I am using a clear theme I got from starkerstheme.com
When adding an image directly to the code I used:

<img src="<?= $theme ?>/images/logo.png"/>

But the image is not showing up, also I tried to add it to the media library and it’s still not rendering.

Related posts

Leave a Reply

8 comments

  1. <?php echo get_template_directory_uri(); ?> 
    

    as suggested gets the PARENT theme, which is OK but if you’ve developed a child theme (as recommended by WordPress people) you need:

    <img src="<?php echo get_stylesheet_directory_uri(); ?>/img/Logo.png">
    
  2. Just go to your dashboard and upload your picture in the media section, then select it you’ll see the image options .. then copy it’s url
    <img src="your/copied/url"/>
    This aslo works for me in localhost

  3. You might need to do the full <img src="<?php echo $theme; ?>/images/logo.png"/>

    Update I didn’t read your question closely enough. If you’re using the media library for the image, you’ll need to specify the actual path to the image. You can figure this out from within the media library, but it’s probably site_url/wp-content/uploads/2012/01/filename.jpg

    In short, if you uploaded it in media, it wouldn’t actually be in your theme.

  4. <?php bloginfo('template_directory'); ?>/

    use for internal root folder in images to place on theme on wordpress.
    The forward slash is needed for the image to show

  5. Remove the = after <?

    <img src="<? $theme ?>/images/logo.png"/>

    in fact, I’d probably do something like this:

    <img src= <?php $theme ?> . "/images/logo.png"/>

  6. on 2021…

    Just name the image as screenshot.png [ recommended image size (currently) is 1200px wide by 900px ] and put it on theme’s top-level directory (where the style.css file is )

    and that’s all you need to do.