The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

PHP image paths in pages to avoid absolute paths (4 posts)

  1. Scorix
    Posted 6 years ago #

    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.

  2. Scorix
    Posted 6 years ago #

    Doesn't anyone have any input on this?

  3. syncbox
    Posted 6 years ago #

    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. example.com) and replace it with the destination site's equivalent (eg. myblog.com)

  4. Baki Goxhaj
    Posted 6 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.