• Resolved Mav3000

    (@mav3000)


    Hi, I am fairly new to PHP but have been working all week on a WordPress Theme for my site. This is locally at the moment (no online link).

    I have numerous images in files such as header.php and sidebar.php. These are linked from my site’s ‘images’ directory (e.g. <img src=”images/image.jpg” /> ).

    However, since enabling pretty permalinks, all of my Pages do not show the images. I know that this is because the directory to the images is no longer correct due to the pretty permalinks adding ‘folders’ to the URL of the page I am looking at.

    How can I fix this?

    Thanks, Richard

Viewing 4 replies - 1 through 4 (of 4 total)
  • If your images theme is in folder {web-root}/images, you need a forward slash before the folder name, as in <img src="/images/image.jpg" />

    FYI, typically in WordPress themes, a theme’s images reside in a folder beneath the theme folder:
    /wp-content/themes/{theme-name}/images

    Thread Starter Mav3000

    (@mav3000)

    Hi, My CSS file links to the images using the path ‘images/image.jpg’ and works fine, but the images included in the template php files do not show up on any pages other than the home page.

    I have the images in the templates files in both the ‘images’ folder in my site’s root folder, as well copies in the ‘images’ folder in the wordpress theme folder. They still don’t show up.

    is there some sort of wordpress variable I can use in the url of the images that points them to the siteroot? or should I just use the complete URL of the images in the template files?

    Surely everyone else with permalinks enabled would have the same issue wouldn’t they?

    Hi

    This is an HTML/CSS thing, not a WordPress thing. image locations in a stylesheet are relative to the location of the stylesheet. In other words, if the stylesheet is http://mydomain.com/wordpress/wp-contents/themes/mytheme/style.css, the when you reference url(images/myimage.jpg) in the style sheet, the browser is looking for that image at http://mydomain.com/wordpress/wp-contents/themes/mytheme/images/myimage.jpg

    When you reference them in a template, not in a stylesheet, the relative location is in relation to the webpage URL, not the stylesheet URL.

    In a template one typically refers to the stylesheet image folder like this: <?php bloginfo('template_directory'); ?>/images/myimage.jpg

    Thread Starter Mav3000

    (@mav3000)

    stvwlf – Thank you very much! adding the <?php bloginfo(‘template_directory’); ?> before the image paths has sorted out the problem, and they now work fine.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Enabled Permalinks, Now Template Images Don’t Show’ is closed to new replies.