Support » Themes and Templates » PHP image paths in pages to avoid absolute paths

  • I’ve been using <?php bloginfo('stylesheet_directory'); ?>/images/MyImage.png in my template files, and it’s been working great.

    When I go to the WordPress Dashboard > Pages > Add New and try to use it in my pages though, the image doesn’t show up. I tried using the <?php bloginfo('name'); ?> as well, but that doesn’t work either.

    Does anyone know what the problem might be? There surely must be a way to use the <img> tag in pages and posts without having to use absolute image paths?

    I need to add over a thousand images, so by using absolute paths, I risk having to do a lot of work later if I should move around some files, or rename the theme or something like that.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Doesn’t anyone have any input on this?

    The bloginfo function you are using is going to parse the path anyway as an absolute URL… take a look at the HTML source on any WordPress page or post and you’ll see every reference parsed before display.

    If you are avoiding absolute URLs because you plan to move the site later (like after development) you’ll have to Find and Replace all instances of the original URL (eg. and replace it with the destination site’s equivalent (eg.

    You cannot run PHP code your your post/page editor in WordPress by default. You can do so if you install a plugin (don’t remember the name) which I do not recommend.

    What I suggest you is to upload the images through the post/page image library. To do so, just click on the “Insert an Image” icon just below the post/page title field. This will make your live a lot easier and allow you to manipulate your images as you like.

    Good Luck!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘PHP image paths in pages to avoid absolute paths’ is closed to new replies.