• Hey!

    I have a folder IMAGES inside my custom theme folder.
    All the HTML code is pointing to the images correctly, so the HOME page
    show everything fine.

    Now, I need to add the other HTML static pages,
    so I just create a new page template, but now the new PAGE does not find the images folder because its pointing to the images folder but with the name of the page first.

    So, as this example:

    Home page:

    http://mydomain.com
    is getting the images in the /wp-content/themes/mytheme/images

    New Template page

    http://mydomain.com/pagename
    is trying to get the images at pagename/wp-content/themes/mytheme/images

    Of course that breaks the link,
    so how to solve this issue? how to make all the new pages get the images from the
    theme root folder?

    Thanks for the help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Provided this code is within your theme files, use the WordPress function get_template_directory_uri to automatically find your theme’s folder. The code would look something like:

    <img src="<?php echo get_template_directory_uri(); ?>/images/something.jpg" />

    Thread Starter filete

    (@filete)

    Hi again,

    You mean , I have to call that php function in every HTML img tag?

    Yes, if the code you’re working with is within your theme files.

    If you’re calling it within a single page (ie. you’ve gone to Pages -> Add New and are working on content within that page) you’d have to enter the URL manually:

    <img src="/wp-content/themes/mytheme/images/something.jpg" />

    What you need is the slash before wp-content that tells the browser to look first to the root directory, not within “pagename.”

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Page Template breaks images links?’ is closed to new replies.